Changing ownership of static directory not working in kubernetes

7/26/2020

I am trying to change ownership of static directory in a container but for some reason it's not working but it works on another directory.

securityContext:
  runAsUser: 0
command: ["/bin/sh"]
args:
- -c
- |
  chown -R www-data:www-data /var/www/html/pub/media
  chown -R www-data:www-data /var/www/html/pub/static

When I run kubectl -n magento exec magento-web-dweq34672 -- ls -al var/www/html/pub I see static directory still under root ownership. everytime I Am manually changing it using following which is getting frustrating now, any suggestions

kubectl -n magento exec magento-web-dweq34672 -- chown -R www-data:www-data var/www/html/pub

-- user11931805
containers
docker
kubernetes
magento

2 Answers

7/26/2020

Init container is what you need here, use init container to change the permissions and the ownership.

-- Vaibhav Jain
Source: StackOverflow

7/28/2020

As suggested before you can use initContainer in your deployment spec.

Example:

initContainers:
        - name: my-init
          image: busybox:1.28
          command: [ 'sh', '-c', 'chown -R www-data:www-data var/www/html/pub']

Here you can find more information about initContainer

Another option is rebuild the image with the right permissions.

-- Mr.KoopaKiller
Source: StackOverflow