<p>I am trying to create a <code>PV</code> and <code>PVC</code> which is accessible by a <code>pod</code> and a <code>cronjob</code> too on the same <code>node</code>.</p>
<p>Currently I am using the following <code>yaml</code> file</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: wwwroot
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;wwwroot&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app: wwwroot
  name: wwwroot
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 100Gi
status: {}
</code></pre>
<p>in the <code>statefulSet</code></p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: web
  name: web
spec:
  selector:
    matchLabels:
      app: web
  serviceName: web
  replicas: 1
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: web
        image: xy:latest
        ports:
        - containerPort: 80
        - containerPort: 443
        volumeMounts:
        - mountPath: /app/wwwroot
          name: wwwroot
          subPath: tempwwwroot
      imagePullSecrets:
        - name: xy
      restartPolicy: Always
      serviceAccountName: &quot;&quot;
  volumeClaimTemplates:
    - metadata:
        name: wwwroot
      spec:
        accessModes: [&quot;ReadWriteOnce&quot;]
        resources:
          requests:
            storage: 100Gi    
</code></pre>
<p>This works fine with the <code>pods</code>, but I have a <code>cronjob</code> that needs to access the same wwwroot <code>PV</code>.</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  labels:
    app: import
  name: import
spec:
  schedule: &quot;09 16 * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:  
          containers:
          - name: import
            image: xy:latest
            imagePullPolicy: Always
            volumeMounts:
            - mountPath: /app/wwwroot
              name: wwwroot
              subPath: tempwwwroot
          imagePullSecrets:
           - name: xy
          restartPolicy: OnFailure
          volumes:
          - name: wwwroot
            persistentVolumeClaim:
              claimName: wwwroot
</code></pre>
<p>To the best of my knowledge, you cannot bind these <code>PV</code>s to a folder on the host machine like in <code>Docker</code> (which would be nice, but I can live with that). When I run a <code>kubectl get pvc</code> with the following setup, it seem to use the same <code>PVC</code> name wwwroot, but clearly it is not. I have <code>/bin/bash</code>-d into the <code>pod</code> created by the <code>cronjob</code> and the wwwroot folder does not contain the files from the web <code>pod</code> wwwroot folder.</p>
<p>Any idea what am I doing wrong? Also what is the best option the create <code>PV</code>/<code>PVC</code>s on a local 1 <code>node</code> <code>Kubernetes</code> setup? I was also thinking about to create a <code>NFS share</code> on the host for easier access to the files.</p>
<p>Also when first created the <code>PV</code>/<code>PVC</code> and deployed the web <code>statefulSet</code>, the web <code>pod</code> should populate the wwwroot <code>PV</code> with CSS and JS files, but seems like when it bounds to the <code>PV</code>, it deletes everything from that folder and I have to manually copy those files again. Any workaround on that?</p>

Sugafree
<p>You are mounting pv on two pod created and using pv by setting accessModes: ReadWriteOnce</p>
<p>You can check them below.
<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes</a></p>
<p>Also instant of local you can use storage class NFS volume which can give you read-write-many. I am not sure Storage class local provide it as it is not in official documents. Chk below
<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/persistent-volumes/</a></p>
<p>P.S. Never use storage class in actual deployment as node in k8s come and go.</p>
