0% found this document useful (0 votes)
97 views3 pages

Exercise 9.3: Creating A Persistent Volume Claim (PVC)

Uploaded by

tektitemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views3 pages

Exercise 9.3: Creating A Persistent Volume Claim (PVC)

Uploaded by

tektitemo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

9.6.

LABS 1

Exercise 9.3: Creating a Persistent Volume Claim (PVC)


Before Pods can take advantage of the new PV we need to create a Persistent Volume Claim (PVC).

1. Begin by determining if any currently exist.


student@lfs458-node-1a0a:~$ kubectl get pvc
No resources found.

2. Create a YAML file for the new pvc.


student@lfs458-node-1a0a:~$ vim pvc.yaml

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

student@lfs458-node-1a0a:~$ kubectl get pvc


NAME STATUS VOLUME CAPACITY ACCESSMODES STORAGECLASS AGE
pvc-one Bound pvvol-1 1Gi RWX 4s

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.

student@lfs458-node-1a0a:~$ cp first.yaml nfs-pod.yaml

student@lfs458-node-1a0a:~$ vim nfs-pod.yaml

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

6. Create the pod using the newly edited file.


student@lfs458-node-1a0a:~$ kubectl create -f nfs-pod.yaml
deployment.apps/nginx-nfs created

7. Look at the details of the pod. You may see the daemonset pods running as well.

student@lfs458-node-1a0a:~$ kubectl get pods

LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.
9.6. LABS 3

NAME READY STATUS RESTARTS AGE


nginx-nfs-1054709768-s8g28 1/1 Running 0 3m

student@lfs458-node-1a0a:~$ kubectl describe pod nginx-nfs-1054709768-s8g28


Name: nginx-nfs-1054709768-s8g28
Namespace: default
Node: lfs458-worker/10.128.0.5

<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>

8. View the status of the PVC. It should show as bound.


student@lfs458-node-1a0a:~$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
pvc-one Bound pvvol-1 1Gi RWX 2m

LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.

You might also like