Deploying and configuring the ingress controller for OpenShift or Kubernetes
To deploy the ingress controller for Openshift
- Download the attached file.
Apply the ingress-scc.yaml file by using the following command:
oc apply -f ingress-scc.yamlGet the deploy.yaml file by using the following command:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.0/deploy/static/provider/cloud/deploy.yamlIf you change the ingress configuration and decide not to use the attached deploy.yaml file, make sure that the INGRESS_CLASS value in the configs/infra.config file matches the class in your ingress definition.
- Update the deploy.yaml file to change the kind property of the ingress-nginx-controller from Deployment to DaemonSet.
Apply the deploy.yaml file by using the following command:
oc apply -f deploy.yamlApply the Security Context Constraints (SCC) to service accounts by running the following commands in the order shown:
oc adm policy add-scc-to-user ingress-scc -z default -n ingress-nginx
oc adm policy add-scc-to-user ingress-scc -z ingress-nginx-admission -n ingress-nginx
oc adm policy add-scc-to-user ingress-scc -z ingress-nginx -n ingress-nginxCreate a secret from the trusted certificate and key. Depending on your cluster, run the following command:
oc create secret tls my-tls-secret --cert=/path/to/cert.pem --key=/path/to/privkey.pem -n ingress-nginxIn the ingress-controller, under daemonset, edit the args section to set the default certificate to my-tls-secret:
oc edit daemonset ingress-nginx-controller -n ingress-nginx
...
spec:
containers:
- args:
- /nginx-ingress-controller
- --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller
- --election-id=ingress-controller-leader
- --controller-class=k8s.io/ingress-nginx
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
- --default-ssl-certificate=ingress-nginx/my-tls-secret
...- Configure the ingress controller. Perform the following steps:
Identify the configmap name by running the following command:
kubectl get cm -n <ingress_nginx_namespace>Change the configmap name to use the configmap in your environment by running the following command:
kubectl edit cm <ingress_nginx_configmap> -n <ingress_nginx_namespace>
data:
enable-underscores-in-headers: "true"
proxy-body-size: 250m
server-name-hash-bucket-size: "1024"
ssl-redirect: "false"
use-forwarded-headers: "true"
worker-processes: "40"
- Verify that the pods are running on each worker node.
Verify the version of the ingress controller from one of the pods' logs by using the following command:
oc logs ingress-nginx-controller-XXXXX | lessUpdate the service ingress-nginx-controller and add load balancer IP as an external IP by using the following command:
oc patch service/ingress-nginx-controller -n ingress-nginx -p '{"spec":{"externalIPs":["xxx.xxx.xxx.xxx"]}}'Here, xxx.xxx.xxx.xxx is the IP that the LB_HOST value resolves to.
Update the load balancer settings to point to the correct ports of ingress-nginx-controller service. Check the ingress-nginx-controller service ports by using the following command:
oc -n ingress-nginx get svcExample output:
For example, you will see output like below:
$ oc -n ingress-nginx get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.43.43.12 XXX.XXX.XXX.XXX 80:31764/TCP,443:31864/TCP 24h
ingress-nginx-controller-admission ClusterIP 10.43.46.181 <none> 443/TCP 24h
To deploy the ingress controller for Rancher-based Kubernetes
If you have the ingress-nginx namespace, delete it by running the following commands:
kubectl delete ds -n ingress-nginx nginx-ingress-controller
kubectl -n ingress-nginx delete svc ingress-nginx-controller-admission
kubectl delete clusterrole ingress-nginx
kubectl delete ClusterRoleBinding ingress-nginx
kubectl delete IngressClass nginx
kubectl delete ValidatingWebhookConfiguration ingress-nginx-admission
kubectl delete ns ingress-nginxDownload the psp.yaml file from github by using the following command:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/docs/examples/psp/psp.yamlIf you have the restricted-psp property enabled by default, apply the psp.yaml file by using the following command:
kubectl apply -f psp.yamlGet the deploy.yaml file from github by using the following command:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.0/deploy/static/provider/cloud/deploy.yamlIn the deploy.yaml file, make the following change for the ingress-nginx-controller:
Apply the deploy.yaml file by using the following command:
kubectl apply -f deploy.yamlCreate a secret with the certificate and key to be mounted on the ingress controller pods by using the following command:
kubectl create secret tls my-tls-secret --cert=/path/to/cert.pem --key=/path/to/privkey.pem -n ingress-nginx- Edit the daemonset as described below:
- Add the secret that you created in the args section.
Run the following command:
kubectl edit daemonset ingress-nginx-controller -n ingress-nginxIn the output, set the ingress-class parameter according to your requirement:
...
spec:
containers:
- args:
- /nginx-ingress-controller
- --publish-service=$(POD_NAMESPACE)/ingress-nginx-controller
- --election-id=ingress-controller-leader
- --controller-class=k8s.io/ingress-nginx
- --ingress-class=nginx
- --configmap=$(POD_NAMESPACE)/ingress-nginx-controller
- --validating-webhook=:8443
- --validating-webhook-certificate=/usr/local/certificates/cert
- --validating-webhook-key=/usr/local/certificates/key
- --default-ssl-certificate=ingress-nginx/my-tls-secret
...
- Configure the ingress controller. Perform the following steps:
Identify the configmap name by running the following command:
kubectl get cm -n <ingress_nginx_namespace>Change the configmap name to use the configmap in your environment by running the following command:
kubectl edit cm <ingress_nginx_configmap> -n <ingress_nginx_namespace>
data:
enable-underscores-in-headers: "true"
proxy-body-size: 250m
server-name-hash-bucket-size: "1024"
ssl-redirect: "false"
use-forwarded-headers: "true"
worker-processes: "40"
- Verify that the pods are running on each worker node.
Update the service ingress-nginx-controller and add load balancer IP as an external IP by using the following command:
kubectl patch service/ingress-nginx-controller -n ingress-nginx -p '{"spec":{"externalIPs":["xxx.xx.xx.xxx"]}}'Here, xxx.xxx.xxx.xxx is the IP that the LB_HOST value resolves to.
Update the load balancer settings to point to the correct ports of ingress-nginx-controller service. Check the ingress-nginx-controller service ports by using the following command:
kubectl -n ingress-nginx get svcExample output:
For example, you will see output like below:
$ kubectl -n ingress-nginx get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller LoadBalancer 10.43.43.12 XXX.XXX.XXX.XXX 80:31764/TCP,443:31864/TCP 24h
ingress-nginx-controller-admission ClusterIP 10.43.46.181 <none> 443/TCP 24h