Using a Persistent Volume

To use this persistent storage, create a Kubernetes Deployment and assign a persistent volume claim.

Using File System Storage

The following example uses file system storage:

$ kubectl create -f nginx-deploy.yaml

The following is the content of the nginx-deploy.yaml file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-fss-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-fss
  template:
    metadata:
      labels:
        app: nginx-fss
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        volumeMounts:
        - mountPath: /usr/share/nginx/
          name: data
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: fss-pvc

Using Block Volume Storage

The following example uses block volume storage:

$ kubectl create -f nginx-deploy.yaml

The following is the content of the nginx-deploy.yaml file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-bv-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-bv
  template:
    metadata:
      labels:
        app: nginx-bv
    spec:
      containers:
      - name: nginx
        image: available_internal_registry/nginx:latest
        volumeMounts:
        - mountPath: /usr/share/nginx/
          name: data
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: mynginxclaim

Verify the New Storage Asset

Use the get pod subcommand to show the names of the replicas in the pod:

$ kubectl get pod

Log in to the pod and use the Linux df command to show that the application replicas are using the persistentVolumeClaim storage. The Filesystem column in the df output shows the mount target IP address and the file system export path.