Upgrading Nginx Ingress Controller
To upgrade the NGINX Ingress Controller
To get the ingress-class used for the NGINX Ingress Controller, run the following command:
kubectl get ds -n ingress-nginx -o yaml | grep -i "\-\-ingress-class"Look for --ingress-class in the command output.
Example: --ingress-class=nginxBased on the version of your Kubernetes or OpenShift, run one of the following commands to get the deploy.yaml file for the NGINX Ingress Controller:
To get deploy.yaml file for Nginx Ingress Controller version 1.7.0:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.7.0/deploy/static/provider/cloud/deploy.yamlTo get deploy.yaml file for Nginx Ingress Controller version 1.8.1:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.1/deploy/static/provider/cloud/deploy.yamlTo get deploy.yaml file for Nginx Ingress Controller version 1.9.3:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.3/deploy/static/provider/cloud/deploy.yamlTo get deploy.yaml file for Nginx Ingress Controller version 1.9.5:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.5/deploy/static/provider/cloud/deploy.yamlTo get deploy.yaml file for Nginx Ingress Controller version 1.9.6:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.6/deploy/static/provider/cloud/deploy.yaml
- Make sure that the ingress class (which you verified in Step 1) is mentioned in the deploy.yaml file.
To delete the jobs (ingress-nginx-admission-create and ingress-nginx-admission-patch), run the following command:
kubectl delete job ingress-nginx-admission-create ingress-nginx-admission-patch -n ingress-nginx --ignore-not-found=true- Make the following changes in the deploy.yaml file:
Change the kind field of the ingress-nginx-controller from Deployment to DaemonSet
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
app.kubernetes.io/version: <version of the deploy.yaml>
name: ingress-nginx-controller
namespace: ingress-nginx(If upgrading to Ingress Controller 1.9.3 or later) Under Kind: Daemonset, change the spec.strategy field to spec.updateStrategy.
spec:
minReadySeconds: 0
revisionHistoryLimit: 10
selector:
matchLabels:
app.kubernetes.io/component: controller
app.kubernetes.io/instance: ingress-nginx
app.kubernetes.io/name: ingress-nginx
updateStrategy:
rollingUpdate:
maxUnavailable: 1
type: RollingUpdateIn the args section, set the default certificate to my-tls-secret:
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 # <<<<<<<<<<<<<<(If deploying NGINX Ingress Controller 1.9.5 or later) Under kind: Daemonset, locate securityContext, and then set the value of the flag allowPrivilegeEscalation as true.
securityContext:
allowPrivilegeEscalation: true
- Apply the Security Context Constraints (SCC) to service accounts by running the following commands:
If the version of your OpenShift cluster is lower than 4.14:
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-nginxIf the version of your OpenShift cluster is 4.14 or higher:
oc -n ingress-nginx annotate job.batch/ingress-nginx-admission-patch openshift.io/required-scc="ingress-scc"
oc -n ingress-nginx annotate job.batch/ingress-nginx-admission-create openshift.io/required-scc="ingress-scc"
oc -n ingress-nginx annotate daemonset.apps/ingress-nginx-controller openshift.io/required-scc="ingress-scc"
To apply the deploy.yaml, run the following command:
kubectl apply -f deploy.yamlTo verify that the NGINX Ingress Controller pods are running on all worker nodes, run the following command:
kubectl -n ingress-nginx get podsTo verify the version of the NGINX Ingress Controller from one of the pod logs, run the following command:
kubectl logs <ingress controller pod> -n ingress-nginx | lessWhere -n ingress-nginx is the ingress namespace.
The pod logs should have the same version of the NGINX Ingress Controller that you installed.To make sure that the same ports of the NGINX Ingress Controller service are configured in the load balancer, run the following command:
kubectl -n ingress-nginx get serviceThe Validating Webhook Configuration blocks the deployment of a few Ingress objects. To delete the Validating Webhook Configuration, run the following command:
kubectl -n ingress-nginx delete ValidatingWebhookConfiguration ingress-nginx-admission
Performing post upgrade task
- In the ingress-nginx namespace, open the nginx-configuration configmap and review the value of allow-snippet-annotations configuration parameter.
- If the value of allow-snippet-annotations is false, set it to true.
allow-snippet-annotations: "true".