[Kubernetes (K8S)] Helm install Ingress Nginx within Kubernetes (K8S)

helm-ingress-nginx-example

ingress-nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer.

You can modify it and use ingress-nginx. There is some examplesabout installing it with Helm in the article.


As of Nov 13, 2020, charts in this repo will no longer be updated. For more information, see the Helm Charts Deprecation and Archive Notice, and Update.


You can use Azure Helm mirror - http://mirror.azure.cn/kubernetes/charts/ to replace https://kubernetes-charts.storage.googleapis.com

Prerequisites

  • Kubernetes (K8S)
    Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

  • Helm
    Helm is the best way to find, share, and use software built for Kubernetes.

How to Install

1
2
3
4
# git clone example.
$ git clone --recursive https://github.com/CloudoLife/helm-ingress-nginx-example

$ cd helm-ingress-nginx-example

Custom Values.yaml

Edit values.yaml in helm-ingress-nginx-example directory, and replace content within < and >.

How to expose Ingress Nginx controller pod outside Kuberneters(K8S):

  • use hostNetwork to expose Ingress Nginx controller pod.
  • run Ingress Nginx controller as a DaemonSet.
  • specify nodeSelector with Your Node Host Name or Label.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# cat values.yaml

# ingress-nginx/values.yaml at master · kubernetes/ingress-nginx
# https://github.com/kubernetes/ingress-nginx/blob/master/charts/ingress-nginx/values.yaml

# helm install stable/ingress-nginx --set controller.hostNetwork=true,controller.service.type="",controller.kind=DaemonSet
# https://medium.com/@craignewtondev/how-to-fix-kubernetes-namespace-deleting-stuck-in-terminating-state-5ed75792647e

## nginx configuration
## Ref: https://github.com/kubernetes/ingress/blob/master/controllers/nginx/configuration.md
##
controller:

# Required for use with CNI based kubernetes installations (such as ones set up by kubeadm),
# since CNI and hostport don't mix yet. Can be deprecated once https://github.com/kubernetes/kubernetes/issues/23920
# is merged
hostNetwork: true

# DaemonSet or Deployment
#
kind: DaemonSet

service:

type: "ClusterIP"

dnsPolicy: "ClusterFirstWithHostNet"

# ## Node tolerations for server scheduling to nodes with taints
# ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
# ##
# tolerations:
# - operator: "Exists"

# Node labels for default backend pod assignment
# Ref: https://kubernetes.io/docs/user-guide/node-selection/
#
nodeSelector:
kubernetes.io/hostname: <Your Node Host Name or Label>

admissionWebhooks:
enabled: false

Install by Helm

Helm install ingress-nginx within ingress-nginx namespace. Please create ingress-nginx namespace first if not exist.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# crate namespace:
$ kubectl create namespace ingress-nginx

# Add the Helm repository:
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
$ helm repo add stable http://mirror.azure.cn/kubernetes/charts/
# (Deprecation) $ helm repo add stable https://kubernetes-charts.storage.googleapis.com

# Update your local Helm chart repository cache:
$ helm repo update

# To install the ingress-nginx Helm chart:
$ helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx -f values.yaml

See Helm release about ingress-nginx.

1
2
3
$ helm list --namespace ingress-nginx
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
ingress-nginx ingress-nginx 2 2020-09-26 00:29:42.437531 +0800 +0800 deployed ingress-nginx-3.3.0 0.35.0

See pods about ingress-nginx.

1
2
3
$ kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
ingress-nginx-controller-jz4ph 1/1 Running 4 13d

Common Annotations

You can add these Kubernetes annotations to specific Ingress objects to customize their behavior.

Custom max body size

For NGINX, an 413 error will be returned to the client when the size in a request exceeds the maximum allowed size of the client request body. This size can be configured by the parameter client_max_body_size.

To configure this setting globally for all Ingress rules, the proxy-body-size value may be set in the NGINX ConfigMap. To use custom values in an Ingress rule define these annotation:

1
nginx.ingress.kubernetes.io/proxy-body-size: 8m

FAQs

err services “ingress-nginx” not found

1
W0530 05:54:54.909996       6 queue.go:130] requeuing &ObjectMeta{Name:sync status,GenerateName:,Namespace:,SelfLink:,UID:,ResourceVersion:,Generation:0,CreationTimestamp:0001-01-01 00:00:00 +0000 UTC,DeletionTimestamp:<nil>,DeletionGracePeriodSeconds:nil,Labels:map[string]string{},Annotations:map[string]string{},OwnerReferences:[],Finalizers:[],ClusterName:,Initializers:nil,ManagedFields:[],}, err services "ingress-nginx" not found

Create a manifest file for ingress-nginx Service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Service-Nginx-Ingress.yaml

apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
spec:
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
- name: https
port: 443
targetPort: 443
protocol: TCP
selector:
app: ingress-nginx

Create Service resources:

1
2
kubectl apply -f Service-Nginx-Ingress.yaml
service/ingress-nginx created

Check Service resources:

1
2
3
kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx ClusterIP 10.111.200.172 <none> 80/TCP,443/TCP 3d4h

See Flood of ingress-nginx service error in controller · Issue #3005 · kubernetes-sigs/kubespray - https://github.com/kubernetes-sigs/kubespray/issues/3005 to learn more.

References

[1] CloudoLife/helm-ingress-nginx-example: Examples about Helm install Nginx Ingress. https://github.com/CloudoLife/helm-ingress-nginx-example - https://github.com/CloudoLife/helm-ingress-nginx-example

[2] Welcome - NGINX Ingress Controller - https://kubernetes.github.io/ingress-nginx/

[3] kubernetes/ingress-nginx: NGINX Ingress Controller for Kubernetes - https://github.com/kubernetes/ingress-nginx

[4] Helm - https://helm.sh/

[5] Kubernetes - https://kubernetes.io/

[6] Annotations - NGINX Ingress Controller - s://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations