k8s.github.io

Using PVC in PODs

In this section, we will take a look at Using PVC in PODs

Create the Persistent Volume

pv-definition.yaml

kind: PersistentVolume
apiVersion: v1
metadata:
    name: pv-vol1
spec:
    accessModes: [ "ReadWriteOnce" ]
    capacity:
     storage: 1Gi
    hostPath:
     path: /tmp/data
$ kubectl create -f pv-definition.yaml

Create the Persistent Volume Claim

pvc-definition.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes: [ "ReadWriteOnce" ]
  resources:
   requests:
     storage: 1Gi
$ kubectl create -f pvc-definition.yaml

Create a Pod

pod-definition.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/var/www/html"
        name: web
  volumes:
    - name: web
      persistentVolumeClaim:
        claimName: myclaim
$ kubectl create -f pod-definition.yaml

List the Pod,Persistent Volume and Persistent Volume Claim

$ kubectl get pod,pvc,pv

References Docs