Mounting nginx webroot into PersistenVolume

12/19/2018

I'm trying to create a basic php-fpm and nginx setup.

I have 2 docker images, one running php-fpm and another running nginx (custom one including my php code)

I have created a PersistentVolumeClaim which both containers use.

My problem is that when i exec into the nginx pod, the webroot folder is empty.

I'm currently creating a volume for /var/www/html and in the my nginx image, i'm COPYing my index.php into /var/www/html

I have the following:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
    name: pv-claim
spec:
    accessModes:
    - ReadWriteOnce
    resources:
        requests:
            storage: 2Gi

I have the following in my nginx-deployment.yaml

    spec:
        containers:
        - name: nginx
          image: MY_CUSTOM/IMAGE:v1
          ports:
          - containerPort: 80
            name: nginx
          volumeMounts:
          - name: persistent-storage
            mountPath: /var/www/html
          - name: nginx-config-volume
            mountPath: /etc/nginx/nginx.conf
            subPath: nginx.conf
        volumes:
        - name: persistent-storage
          persistentVolumeClaim:
              claimName: pv-claim
        - name: nginx-config-volume
          configMap:
              name: nginx-config

What I'd expect is that what is in the docker image under /var/www/html would be inside the volume.

Unless I'm totally incorrect. If so, how would I get my app inside the volume mount?

Thanks

-- sipher_z
kubernetes

0 Answers