title: how to mount volumes as non-root on kubernetes
body: <p>I am trying to create a statefulset that runs zookeper, but I want it to run as non-root (i.e. under the zookeper user).<br />
  This is the image used for this:</p>
  <p><a href="https://github.com/kubernetes-retired/contrib/blob/master/statefulsets/zookeeper/Dockerfile" rel="nofollow noreferrer">https://github.com/kubernetes-retired/contrib/blob/master/statefulsets/zookeeper/Dockerfile</a></p>
  <p>This is how I am trying to mount the volumes (Apparently I need a init container according to <a href="https://serverfault.com/questions/906083/how-to-mount-volume-with-specific-uid-in-kubernetes-pod">this</a>):</p>
  <pre><code>      initContainers:
        # Changes username for volumes
        - name: changes-username
          image: busybox
          command:
          - /bin/sh
          - -c
          - |
            chown -R 1000:1000 /var/lib/zookeeper /etc/zookeeper-conf # &lt;&lt;&lt;&lt;--- this returns
            # cannot change ownership, permission denied
            # read-only filesystem.
  
        containers:
        - name: zookeeper
          imagePullPolicy: IfNotPresent
          image: my-repo/k8szk:3.4.14
          command:
          - sh
          - -c
          - |
            zkGenConfig.sh # The script right here requires /var/lib/zookeper to be owned by zookeper user.
                           # Initially zookeeper user does own it as per the dockerfile above,
                           # but when mounting the volume, the directory becomes owned by root
                           # hence the script fails.
          volumeMounts:
          - name: zk-data
            mountPath: /var/lib/zookeeper
          - name: zk-log4j-config
            mountPath: /etc/zookeeper-conf
  </code></pre>
  <p>I also tried to add the securityContext: <code>fsGroup: 1000</code> with no change.</p>