Share content of a container with another on kubernetes

5/9/2019

here is what i'm trying to achieve :

I have two containers sharing a volume, my first one is a php container, it constains all the file from my project (html, js, whatoever)

The second one is a front end server, say apache

Previously I was sharing a volume in my docker compose and all was fine, my apache can see the file from the php container.

Now I'm using kubernetes, I tried to define a shared volume, and it's actually ok but the fact is I lost all my data from php container. I'm actually sharing a volume, if i touch a new file in it, i can see it from the other container. But it seems my initial files (from the php container) aren't there any more

apiVersion: v1
kind: Pod
metadata:
  name: ms
spec:
  restartPolicy: Always
  volumes:
    - name: test-pierre-container-vol
  containers:
  - name: test-ms-php
    image: myappphp:dev
    env:
      - name: DATABASE_URL
        value: "mysql://root:root@mysql:3306/azert"
      - name: APP_ENV
        value: "PROD"
    volumeMounts:
    - name: test-pierre-container-vol
      mountPath: "/var/www/test"
  - name: test-ms-apache
    image: myappapache:dev
    volumeMounts:
    - name: test-pierre-container-vol
      mountPath: "/var/www/html"
    ports:
      - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-ms-php
  labels:
    run: my-ms-php
spec:
  type: NodePort
  ports:
  - port: 8099
    protocol: TCP
    name: http

any idea / advice ?

-- Seb
docker-volume
kubernetes

0 Answers