Attach NGINX Configurations files with Persistence Volume on AWS EKS

9/29/2019

I'am try attach my NGINX configurations files (config, ssl certificates, and others) to my NGINX POD on AWS EKS (Elastic Kubernetes Service). Reading about this i'am using Persistence Volume and Persistence Volume Claim as demonstrated on follow tutorial (https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/).

My scenario is: i need to attach the configurations files localizated on /mnt/data into NGINX POD.

Persistent Volume:

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

Persistent Volume Claim:

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

NGINX POD:

apiVersion: v1
kind: Pod
metadata:
  name: task-pv-pod
spec:
  volumes:
    - name: task-pv-storage
      persistentVolumeClaim:
        claimName: task-pv-claim
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: task-pv-storage

After running the Persistent Volume, Persistent Volume Claim and NGINX POD and access the running NGINX POD with /bin/bash the data that is located on my cluster at /mnt/data should be inside the /usr/share/nginx/html folder, correct? But when I access NGINX pod in the /usr/share/nginx/html folder my /mnt/data files are not there.

I'm new to development and maybe I'm missing something.

Thanks!

-- Alexandre Barreiro Neto
amazon-eks
aws-eks
kubernetes-pod
kubernetes-pvc
nginx

1 Answer

9/29/2019

If you're creating a pod with nginx image the configuration created by the image will overwrite the existing files in the pod and which will also be reflected in the /mnt/data path also.

You've to move your config files to usr/share/nginx/html after pod creation by using commands in pod.yml file. You can map /mnt/data with tmp folder and use after creation commands to move files to usr/share/nginx/html so everytime you create a new pod your config file will generate in desired path also

-- Prashanna
Source: StackOverflow