简体   繁体   中英

unable to edit nginx.conf file from K8 cluster

I want to edit my Nginx.conf file present inside Nginx controller pod in AKS, but the edit command is not working using the exec command, is there any way else I could edit my nginx.conf .

the command which I tried:

kubectl exec -it nginx-nginx-ingress-controller -n nginx --  cat /etc/nginx/nginx.conf

Generally, it is a bad idea to exec into a pod to do changes. It violates the principle of infrastructure as code. You should extract the nginx.conf file to a ConfigMap and then mount it into the pod.

An example can be found here .

You can then edit the ConfigMap when needing to update the nginx config. Remember to redeploy the Pod to make the config apply.

yh, seems this is also working. tried an alternative way:

Edit/add the properties to change in ingress.yaml and redeploy it. the changes will then reflect in nginx.conf

As mentioned by CrowDev, it's not good practice to update the config of Nginx controller like that.

Nginx controller is the backend of the ingress you can use the config map to update the configuration of the Nginx controller and redeploy the pod of the controller.

Some of the Nginx controller config could be also overwritten using the ingress config and annotation inside it.

You can read more about annotation here: https://docs.nginx.com/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/

I read from the official you are able to configure or modify the nginx.conf through annotation or configmap.

what you need is to modify your ingress file. first, check your ingress by

kubectl get ingress -A

you will see your ingress there, how did you create the ingress? of course, you execute the ingress file which is the YAML file. now you need to edit the file and add some annotation annotation or confgimap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM