|
| 1 | +# Installing the Ingress Controller |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +Make sure you have access to the Ingress controller image: |
| 6 | + |
| 7 | +* For NGINX Ingress controller, use the image `nginxdemos/nginx-ingress` from [DockerHub](https://hub.docker.com/r/nginxdemos/nginx-ingress/). |
| 8 | +* For NGINX Plus Ingress controller, build your own image and push it to your private Docker registry by following the instructions from [here](../nginx-controller). |
| 9 | + |
| 10 | +The installation manifests are located in the [install](../install) folder. In the steps below we assume that you will be running the commands from that folder. |
| 11 | + |
| 12 | +## 1. Create a Namespace, a SA and the Default Secret. |
| 13 | + |
| 14 | +1. Create a namespace and a service account for the Ingress controller: |
| 15 | + ``` |
| 16 | + kubectl apply -f common/ns-and-sa.yaml |
| 17 | +
|
| 18 | + ``` |
| 19 | +
|
| 20 | +1. Create a secret with a TLS certificate and a key for the default server in NGINX: |
| 21 | + ``` |
| 22 | + $ kubectl apply -f common/default-server-secret.yaml |
| 23 | + ``` |
| 24 | +
|
| 25 | + **Note**: The default server returns the Not Found page with the 404 status code for all requests for domains for which there are no Ingress rules defined. For testing purposes we include a self-signed certificate and key that we generated. However, we recommend that you use your own certificate and key. |
| 26 | +
|
| 27 | +1. *Optional*. Create a config map for customizing NGINX configuration (read more about customization [here](../examples/customization)): |
| 28 | + ``` |
| 29 | + $ kubectl apply -f common/nginx-config.yaml |
| 30 | + ``` |
| 31 | +
|
| 32 | +## 2. Configure RBAC |
| 33 | +
|
| 34 | +If RBAC is enabled in your cluster, create a cluster role and bind it to the service account, created in Step 1: |
| 35 | +``` |
| 36 | +$ kubectl apply -f rbac/rbac.yaml |
| 37 | +``` |
| 38 | +
|
| 39 | +**Note**: To perform this step you must be a cluster admin. |
| 40 | +
|
| 41 | +## 3. Deploy the Ingress Controller |
| 42 | +
|
| 43 | +We include two options for deploying the Ingress controller: |
| 44 | +* *Deployment*. Use a Deployment if you plan to dynamically change the number of Ingress controller replicas. |
| 45 | +* *DaemonSet*. Use a DaemonSet for deploying the Ingress controller on every node or a subset of nodes. |
| 46 | +
|
| 47 | +### 3.1 Create a Deployment |
| 48 | +
|
| 49 | +For NGINX, run: |
| 50 | +``` |
| 51 | +$ kubectl apply -f deployment/nginx-ingress.yaml |
| 52 | +``` |
| 53 | +
|
| 54 | +For NGINX Plus, run: |
| 55 | +``` |
| 56 | +$ kubectl apply -f deployment/nginx-plus-ingress.yaml |
| 57 | +``` |
| 58 | +
|
| 59 | +**Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built. |
| 60 | +
|
| 61 | +Kubernetes will create one Ingress controller pod. |
| 62 | +
|
| 63 | +
|
| 64 | +### 3.2 Create a DaemonSet |
| 65 | +
|
| 66 | +For NGINX, run: |
| 67 | +``` |
| 68 | +$ kubectl apply -f daemon-set/nginx-ingress.yaml |
| 69 | +``` |
| 70 | +
|
| 71 | +For NGINX Plus, run: |
| 72 | +``` |
| 73 | +$ kubectl apply -f daemon-set/nginx-plus-ingress.yaml |
| 74 | +``` |
| 75 | +
|
| 76 | +**Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built. |
| 77 | +
|
| 78 | +Kubernetes will create an Ingress controller pod on every node of the cluster. Read [this doc](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) to learn how to run the Ingress controller on a subset of nodes, instead of every node of the cluster. |
| 79 | +
|
| 80 | +### 3.3 Check that the Ingress Controller is Running |
| 81 | +
|
| 82 | +Run the following command to make sure that the Ingress controller pods are running: |
| 83 | +``` |
| 84 | +$ kubectl get pods --namespace=nginx-ingress |
| 85 | +``` |
| 86 | +
|
| 87 | +## 4. Get Access to the Ingress Controller |
| 88 | +
|
| 89 | +**If you created a daemonset**, ports 80 and 443 of the Ingress controller container are mapped to the same ports of the node where the container is running. To access the Ingress controller, use those ports and an IP address of any node of the cluster where the Ingress controller is running. |
| 90 | +
|
| 91 | +**If you created a deployment**, below are two options for accessing the Ingress controller pods. |
| 92 | +
|
| 93 | +### 4.1 Service with the Type NodePort |
| 94 | +
|
| 95 | +Create a service with the type *NodePort*: |
| 96 | +``` |
| 97 | +$ kubectl create -f service/nodeport.yaml |
| 98 | +``` |
| 99 | +Kubernetes will allocate two ports on every node of the cluster. To access the Ingress controller, use an IP address of any node of the cluster along with two allocated ports. Read more about the type NodePort [here](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport). |
| 100 | +
|
| 101 | +### 4.2 Service with the Type LoadBalancer |
| 102 | +
|
| 103 | +Create a service with the type *LoadBalancer*. Kubernetes will allocate and configure a cloud load balancer for load balancing the Ingress controller pods. |
| 104 | +
|
| 105 | +Create a service using a manifest for your cloud provider: |
| 106 | +* For GCP or Azure, run: |
| 107 | + ``` |
| 108 | + $ kubectl apply -f service/loadbalancer.yaml |
| 109 | + ``` |
| 110 | +* For AWS, run: |
| 111 | + ``` |
| 112 | + $ kubectl apply -f service/loadbalancer-aws.yaml |
| 113 | + ``` |
| 114 | + Kubernetes will allocate a Classic Load Balancer (ELB) in TCP mode with the PROXY protocol enabled to pass the client's information (the IP address and the port). NGINX must be configured to use the PROXY protocol: |
| 115 | + * Add the following keys to the config map file `nginx-config.yaml` from the Step 1 : |
| 116 | + ``` |
| 117 | + proxy-protocol: "True" |
| 118 | + real-ip-header: "proxy_protocol" |
| 119 | + set-real-ip-from: "0.0.0.0/0" |
| 120 | + ``` |
| 121 | + * Update the config map: |
| 122 | + ``` |
| 123 | + kubectl apply -f common/nginx-config.yaml |
| 124 | + ``` |
| 125 | + **Note**: For AWS, additional options regarding an allocated load balancer are available, such as the type of a load balancer and SSL termination. Read [this doc](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer) to learn more. |
| 126 | +
|
| 127 | +Use the public IP of the load balancer to access the Ingress controller. To get the public IP: |
| 128 | +* For GCP or Azure, run: |
| 129 | + ``` |
| 130 | + $ kubectl get svc nginx-ingress --namespace=nginx-ingress |
| 131 | + ``` |
| 132 | +* In case of AWS ELB, the public IP is not reported by kubectl, as the IP addresses of the ELB are not static and you should not rely on them, but rely on the ELB DNS name instead. However, you can use them for testing purposes. To get the DNS name of the ELB, run: |
| 133 | + ``` |
| 134 | + $ kubectl describe svc nginx-ingress --namespace=nginx-ingress |
| 135 | + ``` |
| 136 | + You can resolve the DNS name into an IP address using `nslookup`: |
| 137 | + ``` |
| 138 | + $ nslookup <dns-name> |
| 139 | + ``` |
| 140 | +
|
| 141 | +Read more about the type LoadBalancer [here](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer). |
| 142 | +
|
| 143 | +## 5. Access the Live Activity Monitoring Dashboard |
| 144 | +
|
| 145 | +For NGINX Plus, you can access the live activity monitoring dashboard: |
| 146 | +1. Use `kubectl port-forward` command to forward connections to port 8080 on your local machine to port 8080 of an NGINX Plus Ingress controller pod (replace <nginx-plus-ingress-pod> with the actual name of a pod): |
| 147 | + ``` |
| 148 | + $ kubectl port-forward <nginx-plus-ingress-pod> 8080:8080 --namespace=nginx-ingress |
| 149 | + ``` |
| 150 | +1. Open your browser at http://127.0.0.1:8080/status.html to access the dashboard. |
| 151 | +
|
| 152 | +## Uninstall the Ingress Controller |
| 153 | +
|
| 154 | +Delete the `nginx-ingress` namespace to uninstall the Ingress controller along with all the auxiliary resources that were created: |
| 155 | +``` |
| 156 | +$ kubectl delete namespace nginx-ingress |
| 157 | +``` |
0 commit comments