Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom nginx.tmpl fails at startup: /etc/nginx/template filesystem is read-only #2861

Closed
bgagnon opened this issue Jul 27, 2018 · 6 comments

Comments

@bgagnon
Copy link

bgagnon commented Jul 27, 2018

Is this a BUG REPORT or FEATURE REQUEST?: Bug report
NGINX Ingress controller version: (dev)
Kubernetes version: 1.10.3

Environment:

  • Cloud provider or hardware configuration: Docker for Mac

What happened:

Configuring a custom nginx.tmpl is no longer working in latest build.

      containers:
      - name: nginx-ingress-controller
        image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:dev
        securityContext:
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
          runAsUser: 33
        volumeMounts:
        - mountPath: /etc/nginx/template
          name: nginx-template-volume
        - mountPath: /var/lib/nginx/
          name: nginx-var-lib
      volumes:
      - name: nginx-template-volume
        configMap:
          name: nginx-configuration
          items:
          - key: nginx.tmpl
            path: nginx.tmpl
      - name: nginx-var-lib
        emptyDir: {}

The Dockerfile's entrypoint wants to set permissions on the directory, but it's read-only because it is mounted from a ConfigMap:

chown: changing ownership of '/etc/nginx/template/nginx.tmpl': Read-only file system
chown: changing ownership of '/etc/nginx/template/..data': Read-only file system
chown: changing ownership of '/etc/nginx/template/..2018_07_27_19_46_12.086463885/nginx.tmpl': Read-only file system
chown: changing ownership of '/etc/nginx/template/..2018_07_27_19_46_12.086463885': Read-only file system
chown: changing ownership of '/etc/nginx/template': Read-only file system

I tried forcing the ConfigMap volume as readOnly: false but it does not help.

@bgagnon
Copy link
Author

bgagnon commented Jul 27, 2018

Looks like this was added in 8107e0f and further refined in df76d4b.
The chown steps cannot work if the directory is mounted from a ConfigMap.

@aledbf
Copy link
Member

aledbf commented Jul 27, 2018

@bgagnon this is my fault. As part to run the ingress controller as a user I made changes to the startup of the container.
Tomorrow I will add e2e tests for custom templates to fix and avoid this regression.
Apologies for the troubles.

@bgagnon
Copy link
Author

bgagnon commented Jul 27, 2018

Also note that setting readOnly: false is a no-op in Kubernetes 1.9+ unless a feature gate is toggled: kubernetes/kubernetes#62099

I can think of one workaround involving an emptyDIr volume and an initContainer that moves nginx.tmpl into place.

@bgagnon
Copy link
Author

bgagnon commented Jul 27, 2018

No worries @aledbf, and thank you for the fast response.

@bgagnon
Copy link
Author

bgagnon commented Jul 27, 2018

This workaround is functional:

      initContainers:
      - name: copy-nginx-template
        image: busybox
        args:
        - cp
        - /tmp/nginx/nginx.tmpl
        - /etc/nginx/template/nginx.tmpl
        volumeMounts:
        - name: nginx-template-volume
          mountPath: /tmp/nginx
        - mountPath: /etc/nginx/template
          name: nginx-template-dir
      volumes:
      - name: nginx-template-dir
        emptyDir: {}
      - name: nginx-var-lib
        emptyDir: {}
      - name: nginx-template-volume
        configMap:
          name: nginx-configuration
          items:
          - key: nginx.tmpl
            path: nginx.tmpl

@aledbf
Copy link
Member

aledbf commented Jul 30, 2018

Closing. Fixed in #2877

@aledbf aledbf closed this as completed Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants