<p>I have problem with PersistentVolume in local K8s cluster. When I am rebooting PC or close and open Desktop Docker I lose data in my PV.</p>
<p>This is my PV config:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pvolume
  labels:
    name: pvolume
spec:
  storageClassName: manual
  volumeMode: Filesystem
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/mnt/data&quot;
</code></pre>
<p>Is there any possibility to keep data and not use external PV provider like GCP volume?</p>
<p><strong>SOLUTION:</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pvolume
  labels:
   name: pvolume
spec:
  capacity:
    storage: 3Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: your-local-storage-class-name
  local:
    path: /c/yourDir
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - docker-desktop
</code></pre>

MMC
<p>As it is mentioned in links I have provided in comment section - read more: <a href="https://github.com/docker/for-win/issues/7023#issuecomment-753536143" rel="nofollow noreferrer">docker-desktop-pv</a>, <a href="https://github.com/docker/for-win/issues/7023#issuecomment-772989137" rel="nofollow noreferrer">docker-desktop-pv-local</a> - solution/workaround is to use different volume type.  Change  <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer">hostPath</a> volume to local. Your <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">PV</a> yaml file should look like:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pvolume
  labels:
    name: pvolume
spec:
  storageClassName: manual
  volumeMode: Filesystem
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  local:
    path: /c/yourDirectory
</code></pre>
<p><code>local.path</code> shows directly where you reference the Windows folder so that you can connect the PersistentVolume locally on a Windows machine.</p>
<blockquote>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer"><code>hostPath</code></a>-  HostPath volume (for single node testing only; WILL NOT WORK in a multi-node cluster; consider using  <code>local</code>  volume instead)
...</li>
<li><a href="https://kubernetes.io/docs/concepts/storage/volumes/#local" rel="nofollow noreferrer"><code>local</code></a> - local storage devices mounted on nodes.</li>
</ul>
</blockquote>
<p>See: <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes" rel="nofollow noreferrer">types-of-pv</a>.</p>
