user11931805
user11931805

Reputation:

Changing ownership of static directory not working in kubernetes

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

Upvotes: 2

Views: 1423

Answers (2)

Mr.KoopaKiller
Mr.KoopaKiller

Reputation: 3962

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.

Upvotes: 1

Vaibhav Jain
Vaibhav Jain

Reputation: 2243

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

Upvotes: 0

Related Questions