<p>I'd like to set up a Persistent Volume (PV and PVC) shared by pods in a <a href="https://kind.sigs.k8s.io/" rel="nofollow noreferrer">kind cluster</a>. However, I need to ensure that the data is persisted on my laptop (host server) as well. Therefore, the volume's path should be on my laptop that I can directly access.</p>
<p>If I delete the <code>kind cluster</code>, the volume should be persisted and not destroyed.</p>
<p>I also want to be able to easily add, update, or copy files from that volume on my host laptop.</p>
<p>How can I make the pods in the <code>Kind cluster</code> aware of this setup?</p>
<p>Please find my <code>kind.yaml</code> file for your reference.</p>
<pre><code>$ kind
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker
</code></pre>

Bill
<p>When you create your kind cluster you can <a href="https://kind.sigs.k8s.io/docs/user/configuration/#extra-mounts" rel="noreferrer">specify host directories to be mounted on a virtual node</a>.  If you do that, then you can configure volumes with <code>hostPath</code> storage, and they will refer to the mount paths on the node.</p>
<p>So you would create a kind config file:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
  - role: control-plane
    extraMounts:
      - hostPath: /home/bill/work/foo
        containerPath: /foo
</code></pre>
<p>and then run</p>
<pre class="lang-sh prettyprint-override"><code>kind create cluster --config kind-config.yaml
</code></pre>
<p>to create the cluster.</p>
<p>In your Kubernetes YAML file, you need to mount that <code>containerPath</code> as a &quot;host path&quot; on the node.  A pod spec might contain in part:</p>
<pre class="lang-yaml prettyprint-override"><code>volumes:
  - name: foo
    hostPath:
      path: /foo  # matches kind containerPath:
containers:
  - name: foo
    volumeMounts:
      - name: foo
        mountPath: /data  # in the container filesystem
</code></pre>
<p>Note that this setup is extremely specific to kind.  Host paths aren't reliable storage in general: you can't control which node a pod gets scheduled on, and both pods and nodes can get deleted in real-world clusters.  In some hosted setups (AWS EKS, Google GKE) you may not be able to control the host content at all.</p>
<p>You might revisit your application design to minimize the need for &quot;files&quot; as first-class objects.  Rather than &quot;update the volume&quot; consider deploying a new Docker image with updated content; rather than &quot;copy files out&quot; consider an HTTP service you can expose through an ingress controller.</p>
