github.com/nginxinc/kubernetes-ingress@v1.12.5/docs-web/installation/installation-with-manifests.md (about) 1 # Installation with Manifests 2 3 This document describes how to install the NGINX Ingress Controller in your Kubernetes cluster using Kubernetes manifests. 4 5 ## Prerequisites 6 7 1. Make sure you have access to the Ingress controller image: 8 * For NGINX Ingress controller, use the image `nginx/nginx-ingress` from [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress). 9 * For NGINX Plus Ingress controller, build your own image and push it to your private Docker registry by following the instructions from [here](/nginx-ingress-controller/installation/building-ingress-controller-image). 10 1. Clone the Ingress controller repo and change into the deployments folder: 11 ``` 12 $ git clone https://github.com/nginxinc/kubernetes-ingress/ 13 $ cd kubernetes-ingress/deployments 14 $ git checkout v1.12.5 15 ``` 16 17 ## 1. Configure RBAC 18 19 1. Create a namespace and a service account for the Ingress controller: 20 ``` 21 $ kubectl apply -f common/ns-and-sa.yaml 22 ``` 23 2. Create a cluster role and cluster role binding for the service account: 24 ``` 25 $ kubectl apply -f rbac/rbac.yaml 26 ``` 27 28 3. (App Protect only) Create the App Protect role and role binding: 29 30 ``` 31 $ kubectl apply -f rbac/ap-rbac.yaml 32 ``` 33 34 **Note**: To perform this step you must be a cluster admin. Follow the documentation of your Kubernetes platform to configure the admin access. For GKE, see the [Role-Based Access Control](https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control) doc. 35 36 ## 2. Create Common Resources 37 38 In this section, we create resources common for most of the Ingress Controller installations: 39 1. Create a secret with a TLS certificate and a key for the default server in NGINX: 40 ``` 41 $ kubectl apply -f common/default-server-secret.yaml 42 ``` 43 44 **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. 45 46 1. Create a config map for customizing NGINX configuration: 47 ``` 48 $ kubectl apply -f common/nginx-config.yaml 49 ``` 50 51 1. Create an IngressClass resource (for Kubernetes >= 1.18): 52 ``` 53 $ kubectl apply -f common/ingress-class.yaml 54 ``` 55 If you would like to set the Ingress Controller as the default one, uncomment the annotation `ingressclass.kubernetes.io/is-default-class`. With this annotation set to true all the new Ingresses without an ingressClassName field specified will be assigned this IngressClass. 56 57 **Note**: The Ingress Controller will fail to start without an IngressClass resource. 58 59 ### Create Custom Resources 60 61 > **Note**: By default, it is required to create custom resource definitions for VirtualServer, VirtualServerRoute, TransportServer and Policy. Otherwise, the Ingress Controller pods will not become `Ready`. If you'd like to disable that requirement, configure [`-enable-custom-resources`](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments#cmdoption-global-configuration) command-line argument to `false` and skip this section. 62 63 1. Create custom resource definitions for [VirtualServer and VirtualServerRoute](/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources), [TransportServer](/nginx-ingress-controller/configuration/transportserver-resource) and [Policy](/nginx-ingress-controller/configuration/policy-resource) resources: 64 ``` 65 $ kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml 66 $ kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml 67 $ kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml 68 $ kubectl apply -f common/crds/k8s.nginx.org_policies.yaml 69 ``` 70 71 If you would like to use the TCP and UDP load balancing features of the Ingress Controller, create the following additional resources: 72 1. Create a custom resource definition for [GlobalConfiguration](/nginx-ingress-controller/configuration/global-configuration/globalconfiguration-resource) resource: 73 ``` 74 $ kubectl apply -f common/crds/k8s.nginx.org_globalconfigurations.yaml 75 ``` 76 77 > **Feature Status**: The TransportServer, GlobalConfiguration and Policy resources are available as a preview feature: it is suitable for experimenting and testing; however, it must be used with caution in production environments. Additionally, while the feature is in preview, we might introduce some backward-incompatible changes to the resources specification in the next releases. 78 79 ### Resources for NGINX App Protect 80 81 If you would like to use the App Protect module, create the following additional resources: 82 83 1. Create a custom resource definition for `APPolicy`, `APLogConf` and `APUserSig`: 84 85 ``` 86 $ kubectl apply -f common/crds/appprotect.f5.com_aplogconfs.yaml 87 $ kubectl apply -f common/crds/appprotect.f5.com_appolicies.yaml 88 $ kubectl apply -f common/crds/appprotect.f5.com_apusersigs.yaml 89 ``` 90 91 ## 3. Deploy the Ingress Controller 92 93 We include two options for deploying the Ingress controller: 94 * *Deployment*. Use a Deployment if you plan to dynamically change the number of Ingress controller replicas. 95 * *DaemonSet*. Use a DaemonSet for deploying the Ingress controller on every node or a subset of nodes. 96 97 > Before creating a Deployment or Daemonset resource, make sure to update the [command-line arguments](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments) of the Ingress Controller container in the corresponding manifest file according to your requirements. 98 99 ### 3.1 Run the Ingress Controller 100 * *Use a Deployment*. 101 When you run the Ingress Controller by using a Deployment, by default, Kubernetes will create one Ingress controller pod. 102 103 For NGINX, run: 104 ``` 105 $ kubectl apply -f deployment/nginx-ingress.yaml 106 ``` 107 108 For NGINX Plus, run: 109 ``` 110 $ kubectl apply -f deployment/nginx-plus-ingress.yaml 111 ``` 112 113 **Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built. 114 115 * *Use a DaemonSet*: 116 When you run the Ingress Controller by using a DaemonSet, Kubernetes will create an Ingress controller pod on every node of the cluster. 117 118 **See also:** See the Kubernetes [DaemonSet docs](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) to learn how to run the Ingress controller on a subset of nodes instead of on every node of the cluster. 119 120 For NGINX, run: 121 ``` 122 $ kubectl apply -f daemon-set/nginx-ingress.yaml 123 ``` 124 125 For NGINX Plus, run: 126 ``` 127 $ kubectl apply -f daemon-set/nginx-plus-ingress.yaml 128 ``` 129 130 **Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built. 131 132 ### 3.2 Check that the Ingress Controller is Running 133 134 Run the following command to make sure that the Ingress controller pods are running: 135 ``` 136 $ kubectl get pods --namespace=nginx-ingress 137 ``` 138 139 ## 4. Get Access to the Ingress Controller 140 141 **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. 142 143 **If you created a deployment**, below are two options for accessing the Ingress controller pods. 144 145 ### 4.1 Create a Service for the Ingress Controller Pods 146 147 * *Use a NodePort service*. 148 149 Create a service with the type *NodePort*: 150 ``` 151 $ kubectl create -f service/nodeport.yaml 152 ``` 153 154 Kubernetes will randomly 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 the two allocated ports. 155 156 > Read more about the type NodePort in the [Kubernetes documentation](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport). 157 158 159 * *Use a LoadBalancer service*: 160 161 1. Create a service using a manifest for your cloud provider: 162 * For GCP or Azure, run: 163 ``` 164 $ kubectl apply -f service/loadbalancer.yaml 165 ``` 166 * For AWS, run: 167 ``` 168 $ kubectl apply -f service/loadbalancer-aws-elb.yaml 169 ``` 170 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: 171 * Add the following keys to the config map file `nginx-config.yaml` from the Step 2: 172 ``` 173 proxy-protocol: "True" 174 real-ip-header: "proxy_protocol" 175 set-real-ip-from: "0.0.0.0/0" 176 ``` 177 * Update the config map: 178 ``` 179 kubectl apply -f common/nginx-config.yaml 180 ``` 181 **Note**: For AWS, additional options regarding an allocated load balancer are available, such as the type of a load balancer and SSL termination. Read the [Kubernetes documentation](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer) to learn more. 182 183 Kubernetes will allocate and configure a cloud load balancer for load balancing the Ingress controller pods. 184 2. Use the public IP of the load balancer to access the Ingress controller. To get the public IP: 185 * For GCP or Azure, run: 186 ``` 187 $ kubectl get svc nginx-ingress --namespace=nginx-ingress 188 ``` 189 * In case of AWS ELB, the public IP is not reported by `kubectl`, because the ELB IP addresses are not static. In general, you should rely on the ELB DNS name instead of the ELB IP addresses. However, for testing purposes, you can get the DNS name of the ELB using `kubectl describe` and then run `nslookup` to find the associated IP address: 190 ``` 191 $ kubectl describe svc nginx-ingress --namespace=nginx-ingress 192 ``` 193 You can resolve the DNS name into an IP address using `nslookup`: 194 ``` 195 $ nslookup <dns-name> 196 ``` 197 198 The public IP can be reported in the status of an ingress resource. See the [Reporting Resources Status doc](/nginx-ingress-controller/configuration/global-configuration/reporting-resources-status) for more details. 199 200 > Learn more about type LoadBalancer in the [Kubernetes documentation](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer). 201 202 ## Uninstall the Ingress Controller 203 204 1. Delete the `nginx-ingress` namespace to uninstall the Ingress controller along with all the auxiliary resources that were created: 205 ``` 206 $ kubectl delete namespace nginx-ingress 207 ``` 208 1. Delete the ClusterRole and ClusterRoleBinding: 209 ``` 210 $ kubectl delete clusterrole nginx-ingress 211 $ kubectl delete clusterrolebinding nginx-ingress 212 ``` 213 1. Delete the Custom Resource Definitions: 214 215 **Note**: This step will also remove all associated Custom Resources. 216 217 ``` 218 $ kubectl delete -f common/crds/ 219 ```