Helm chart MongoDb cannot create directory permisions

12/10/2021

I try to deploy mongodb with helm and it gives this error:

mkdir: cannot create directory /bitnami/mongodb/data : permision denied.

I also tried this solution:

sudo chown -R 1001 /tmp/mongo

but it says no this directory.

-- Onur AKKÖSE
devops
helm3
kubernetes
kubernetes-helm

1 Answer

12/10/2021

You have permission denied on /bitnami/mongodb/data and you are trying to modify another path: /tmp/mongo. It is possible that you do not have such a directory at all. You need to change the owner of the resource for which you don't have permissions, not random (non-related) paths :)

You've probably seen this github issue and this answer:

You are getting that error message because the container can't mount the /tmp/mongo directory you specified in the docker-compose.yml file.

As you can see in our changelog, the container was migrated to the non-root user approach, that means that the user 1001 needs read/write permissions in the /tmp/mongo folder so it can be mounted and used. Can you modify the permissions in your local folder and try to launch the container again?

sudo chown -R 1001 /tmp/mongo

This method will work if you are going to mount the /tmp/mongo folder, which is actually not quite a common behavior. Look for another answer:

Please note that mounting host path volumes is not the usual way to work with these containers. If using docker-compose, it would be using docker volumes (which already handle the permission issue), the same would apply with Kubernetes and the MongoDB helm chart, which would use the securityContext section to ensure the proper permissions.

In your situation, you'll just have change owner to the path /bitnami/mongodb/data or to use Security Context on your Helm chart and everything should work out for you.

Probably here you can find the most interesting part with example context:

securityContext:
  runAsUser: 1000
  runAsGroup: 3000
  fsGroup: 2000
  fsGroupChangePolicy: "OnRootMismatch"
-- Mikołaj Głodziak
Source: StackOverflow