<p>I successfully created pod <code>shinyinfo-jenkins-pod.yaml</code>, and <code>shinyinfo-jenkins-svc.yaml</code>, and I could see pod is running. In the pod yaml file, I mount two volumes. But how to change pod's directory access right after pod runs?</p>

<p>I use command as follows:  </p>

<pre><code>[master@master1 ~]$ sudo kubectl exec -it shinyinfo-jenkins -- /bin/bash
jenkins@shinyinfo-jenkins:/$
jenkins@shinyinfo-jenkins:/$
jenkins@shinyinfo-jenkins:/$ chmod 777 /var/jenkins_home
chmod: changing permissions of '/var/jenkins_home': Operation not permitted
jenkins@shinyinfo-jenkins:/$ sudo chmod 777 /var/jenkins_home
bash: sudo: command not found
jenkins@shinyinfo-jenkins:/$ su
su: must be run from a terminal
</code></pre>

<p>As one could see from above, I have no way to change mounted directory access right.</p>

<p>shinyinfo-jenkins-pod.yaml file:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
 name: shinyinfo-jenkins
 labels:
   app: shinyinfo-jenkins
spec:
 containers:
   - name: shinyinfo-jenkins
     image: shinyinfo_jenkins
     imagePullPolicy: Never
     ports:
       - containerPort: 8080
         containerPort: 50000
     volumeMounts:
     - mountPath: /devops/password
       name: jenkins-password
     - mountPath: /var/jenkins_home
       name: jenkins-home
 volumes:
   - name: jenkins-password
     hostPath:
       path: /jenkins/password
   - name: jenkins-home
     hostPath:
       path: /jenkins
</code></pre>

user84592
<p>The files or directories created on the underlying hosts are only writable by root. You either need to run your process as root in a <a href="https://kubernetes.io/docs/user-guide/security-context" rel="nofollow noreferrer">privileged Containe</a>r or modify the file permissions on the host to be able to write to a hostPath volume.(ref:<a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/#hostpath</a>).</p>

<p>To enable privileged mode:</p>

<pre><code>spec:
 containers:
   securityContext:
     privileged: true # Processes in privileged containers are essentially equivalent to root on the host.
</code></pre>
