skip to Main Content

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

4

Answers


  1. Chosen as BEST ANSWER

    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


  2. 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.

    Login or Signup to reply.
  3. 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/

    Update :

    You can separate out different ingress by their name. if you want to manage different configs or headers you need to separate out ingress for managing different configs.

    Example :

    ingress : 1

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: ingress-one
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/rewrite-target: /
        nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
    spec:
      rules:
      - http:
          paths:
          - path: /one
            pathType: Prefix
            backend:
              service:
                name: one
                port:
                  number: 80
    

    ingress : 2

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: ingress-two
      annotations:
        kubernetes.io/ingress.class: nginx
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /two
            pathType: Prefix
            backend:
              service:
                name: two
                port:
                  number: 80
    

    now nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" will get apply to only one ingress or service.

    Login or Signup to reply.
  4. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search