Mount Kubernetes secret as a file with rw permission

1/23/2019

I am trying to create a file with in a POD from kubernetes sceret, but i am facing one issue like, i am not able to change permission of my deployed files.

I am getting below error, chmod: changing permissions of '/root/.ssh/id_rsa': Read-only file system

I have already apply defaultmode & mode for the same but still it is not working.

volumes:
- name: gitsecret
  secret:
    secretName: git-keys
VolumeMounts:
- mountPath: "/root/.ssh"
  name: gitsecret
  readOnly: false

thank you

-- Dev
kubernetes

2 Answers

1/23/2019

There has been some back and forth over this but presumably you are on a k8s version where configmap and secret are read-only no matter how you set the flag - the issue is https://github.com/kubernetes/kubernetes/issues/62099 I think you'll need to follow the advice on there and create an emptyDir volume to copy the relevant files into.

-- Ryan Dawson
Source: StackOverflow

1/24/2019

As you stated, your version of Kubernetes is 1.10 and documentation for it is available here

You can have a look at the github link @RyanDawson provided, there you will be able to find that this RO flag for configMap and secrets was intentional. It can be disabled using feature gate ReadOnlyAPIDataVolumes. You can follow this guide on how to Disabling Features Using Feature Gates.

As a workaround, you can try this approach:

containers:
  - name: apache
    image: apache:2.4
    lifecycle:
      postStart:
        exec:
          command: ["chown", "www-data:www-data", "/var/www/html/app/etc/env.php"]

You can find explanation inside Kubernetes docs Attach Handlers to Container Lifecycle Events

-- Crou
Source: StackOverflow