<p>I'm new with containers and kubernetes.
What I'm trying to do is to create a pod with access to a local directory.</p>

<p>I have followed the directions from:
<a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">configure persistent volume storage</a></p>

<p>Created my Persistent Volume, Persistent Volume Claim and my pod. </p>

<p>The problem is that the tomcat is not able to write on the shared directory</p>

<p>This is the Persistent Volume:</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-webapp6
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 3Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/opt/test_tomcat/app"
</code></pre>

<p>This is the Persistent Volume Claim:</p>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: pvc-webapp6
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
</code></pre>

<p>This is the tomcat Pod I'm trying to create:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: webapp6
spec:
  containers:
  - image: tomcat:8.0
    name: webapp6
    ports:
      - containerPort: 8080
        name: webapp6
    volumeMounts:
    - mountPath: /usr/local/tomcat/webapps
      name: test-volume
  volumes:
  - name: test-volume
    persistentVolumeClaim:
      claimName: pvc-webapp6
</code></pre>

<p>Its a bit obvious, but this the error on the pod.</p>

<blockquote>
  <p>[root@testserver webapp6-test]# kubectl exec -it webapp6  -- /bin/bash <br/>
  root@webapp6:/usr/local/tomcat# mkdir /usr/local/tomcat/webapps/sample <br/>
  mkdir: cannot create directory ‘/usr/local/tomcat/webapps/sample’: Permission denied</p>
</blockquote>

<p>The issue is in your PVC yaml file where you're not specifying the <code>storageClassName</code>. Hence the PV and PVC couldn't bound to each other. Please replace the PVC yaml file with the following file:</p>

<pre><code>kind: PersistentVolumeClaim
apiVersion: v1
metadata:
   name: pvc-webapp6
spec:
   storageClassName: manual
   accessModes:
      - ReadWriteOnce
   resources:
      requests:
         storage: 3Gi
</code></pre>

<p>Now everything should work. Hope this helps.</p>

<p>I quickly used your yaml to deploy pod and everything is working fine at my end:</p>

<pre><code>[root@Master admin]# kubectl exec -it webapp6 bash
root@webapp6:/usr/local/tomcat#  mkdir /usr/local/tomcat/webapps/sample 
root@webapp6:/usr/local/tomcat# touch /usr/local/tomcat/webapps/sample/a
root@webapp6:/usr/local/tomcat# ls /usr/local/tomcat/webapps/sample/
a
</code></pre>

<p>Now when I look at host, I can see the newly created <code>a</code> file</p>

<pre><code>[root@Master admin]# ls /opt/test_tomcat/app/sample/
a
</code></pre>

<p>So, at least yaml files are working fine.</p>
