Exercise 9.3: Creating A Persistent Volume Claim (PVC)
Exercise 9.3: Creating A Persistent Volume Claim (PVC)
LABS 1
pvc.yaml
1 apiVersion: v1
2 kind: PersistentVolumeClaim
3 metadata:
4 name: pvc-one
5 spec:
6 accessModes:
7 - ReadWriteMany
8 resources:
9 requests:
10 storage: 200Mi
3. Create and verify the new pvc is bound. Note that the size is 1Gi, even though 200Mi was suggested. Only a volume of
at least that size could be used.
student@lfs458-node-1a0a:~$ kubectl create -f pvc.yaml
persistentvolumeclaim/pvc-one created
4. Look at the status of the pv again, to determine if it is in use. It should show a status of Bound.
student@lfs458-node-1a0a:~$ kubectl get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM
STORAGECLASS REASON AGE
pvvol-1 1Gi RWX Retain Bound default/pvc-one
5m
5. Create a new deployment to use the pvc. We will copy and edit an existing deployment yaml file. We will change the
deployment name then add a volumeMounts section under containers and volumes section to the general spec. The
name used must match in both places, whatever name you use. The claimName must match an existing pvc. As shown
in the following example.
LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.
2 CHAPTER 9. VOLUMES AND DATA
nfs-pod.yaml
1 apiVersion: apps/v1beta1
2 kind: Deployment
3 metadata:
4 annotations:
5 deployment.kubernetes.io/revision: "1"
6 generation: 1
7 labels:
8 run: nginx
9 name: nginx-nfs
10 namespace: default
11 resourceVersion: "1411"
12 spec:
13 replicas: 1
14 selector:
15 matchLabels:
16 run: nginx
17 strategy:
18 rollingUpdate:
19 maxSurge: 1
20 maxUnavailable: 1
21 type: RollingUpdate
22 template:
23 metadata:
24 creationTimestamp: null
25 labels:
26 run: nginx
27 spec:
28 containers:
29 - image: nginx
30 imagePullPolicy: Always
31 name: nginx
32 volumeMounts:
33 - name: nfs-vol
34 mountPath: /opt
35 ports:
36 - containerPort: 80
37 protocol: TCP
38 resources: {}
39 terminationMessagePath: /dev/termination-log
40 terminationMessagePolicy: File
41 volumes: #<<-- These four lines
42 - name: nfs-vol
43 persistentVolumeClaim:
44 claimName: pvc-one
45 dnsPolicy: ClusterFirst
46 restartPolicy: Always
47 schedulerName: default-scheduler
48 securityContext: {}
49 terminationGracePeriodSeconds: 30
7. Look at the details of the pod. You may see the daemonset pods running as well.
LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.
9.6. LABS 3
<output_omitted>
Mounts:
/opt from nfs-vol (rw)
<output_omitted>
Volumes:
nfs-vol:
Type: PersistentVolumeClaim (a reference to a PersistentV...
ClaimName: pvc-one
ReadOnly: false
<output_omitted>
LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.