<p>I'm trying to wrap my head around Kubernetes and as an exercise, I want to .igrate my docker-compose setup, which consists of nginx, php-fpm and mysql to a k8s cluster.. While I'm familiar with Docker and docker-compose, I just don't seem to figure out, how to mount a local folder into a Kunernetes pod.</p>

<p>What I want to achieve is something as simple as <code>-v /home/user/www:/var/www/html</code> in Docker into each pod.</p>

<p>But no matter how I configure PersistantVolume, the folders mounted in the pods are empty. I tried Docker Desktop with WSL2, microk8s (snap installed with systemd hack) under WSL2 and minikube under WSL2.</p>

<p>Is this storageclass related? Is this even possible in WSL2? </p>

ad_on_is
<p>The Docker bind-mount model can't really be used in Kubernetes the way you describe.</p>

<p>Kubernetes's model is around a cluster of essentially interchangeable machines.  Say you have 10 systems.  Which one has that HTML content?  How does it get there?  What happens if you need to add another node, or that one node is destroyed?  That you happen to be using a test setup with only a single node doesn't change that design point.</p>

<p>If you're using Kubernetes, you're basically required to build this content into an image, and push it into a registry of some sort.  There are a couple of alternatives (a single <code>index.html</code> file could get stuffed into a ConfigMap; you could use external storage like AWS S3) but mostly you'd have to write a Dockerfile, <code>COPY</code> this into an image, and reference that <code>image:</code> in your deployment spec.</p>

<p>For the particular stack you mention, I've also seen a couple of setups that use a named volume to copy data from the PHP container to the nginx server.  This doesn't work well in Kubernetes: the easier volume types to set up can't be shared between containers, and Kubernetes won't automatically copy content into a volume the way Docker will.  I'd suggest avoiding any sort of filesystem sharing in Kubernetes; it's good practice to also avoid it in plain Docker (the <code>COPY</code>-based image setup will work fine in a single-host Compose setup).</p>
