<p>In kubernetes we try to have a immutable deployment of our PHP code by deploying the php code in a prepackaged container.</p>

<p>By nature kubernetes volume replace the directory with an empty volume, but I would like to keep the data of the php container so we can share that with the nginx container which has a vhost configured to connect to the php container.</p>

<pre><code>---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: serviceability
spec:
  replicas: 1
  template:
    metadata:
     spec:
      containers:
      - name: my-stuff-php
        image: our-php-service-in-fpm-container:latest
        ports:
        - containerPort: 9000
          name: transport
          protocol: TCP
        volumeMounts:
        - name: my-volume
          mountPath: /var/www/html
      - name: my-stuff-nginx
        image: nginx:latest
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        volumeMounts:
        - name: my-volume
          mountPath: /var/www/html
      volumes:
      - name: my-volume
        emptyDir: {}
</code></pre>

<p>A similar setup on docker-compose works as docker-compose behaves different with regards to volumes.</p>

<p>How can I share the existing data in /var/www/html from my php container with the nginx container?</p>

Marco
<p>Kubernetes hasn't mechanism like docker-compose to share some folder as volume. But you can create Persistent Volume (PV) and Persistent Volume Claim (PVC) and share your data between containers.
It is described in <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">documentation</a>
Examples from Docs:</p>

<p>YAML for creating PV</p>

<pre><code>kind: PersistentVolume
apiVersion: v1
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/data"
</code></pre>

<p>Than you make PVC from this volume</p>

<p>YAML:</p>

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

<p>Your YAML for deployment will looks like:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: serviceability
spec:
  replicas: 1
  template:
    metadata:
     spec:
      containers:
      - name: my-stuff-php
        image: our-php-service-in-fpm-container:latest
        ports:
        - containerPort: 9000
          name: transport
          protocol: TCP
        volumeMounts:
        - name: name: task-pv-storage
          mountPath: /var/www/html
      - name: my-stuff-nginx
        image: nginx:latest
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        volumeMounts:
        - name: name: task-pv-storage
          mountPath: /var/www/html
      volumes:
      - name: task-pv-storage
        ersistentVolumeClaim:
        claimName: task-pv-claim
</code></pre>

<p>As a result you will have volume with data which you share between two container in pod.</p>
