Change user and group for a configmap and secret volume mounts

10/7/2021

We are mounting all the volumes as a non-root user inside the container in a pod using the securityContext. However, for all the configmaps and secrets the volumemount user is still root. I tried the initContainer approach without any success.

I searched on net and didn't get any information on changing the user for the volumemounts for configmaps/secrets as a non-root user. Can anyone please help me here?

-- Nishant Kansal
configmap
kubernetes
kubernetes-secrets

1 Answer

10/8/2021

Did you create the user in the docker file and uses the below configuration in Kubernetes?

Dockerfile

RUN useradd nonroot -u 10001
USER 10001

Kubernetes:

securityContext:
  runAsNonRoot: true
  runAsUser: 10001
-- karthik
Source: StackOverflow