Volume Question
CKA exam,volume question,Kubernetes exam question,
Question 7.
– Create a new PersistentVolume named tata-pv. It should have a capacity of 2Gi, accessMode ReadWriteOnce, hostPath /srv/app-config-var.
– Next create a new PersistentVolumeClaim in Namespace project-tiger named tata-pvc . It should request 2Gi storage, accessMode ReadWriteOnce and should not define a storageClassName. The PVC should bound to the PV correctly.
– Finally create a new pod tata in Namespace project-tiger which mounts that volume at /tmp/tata-data. The Pods should be of image httpd:2.4.41-alpine.
Solution: In exam, namespace “project-tige” already created.
To complete this question, we need to create PV, PVC and POD.
1. Create PV:
name=tata-pv,
Capacity=2Gi,
accessMode=ReadWriteOnce,
hostPath=/srv/app-config-var ,
Remember: PV is not namespaced object.
2. Create PVC:
name=tata-pvc,
Capacity=2Gi,
accessMode=ReadWriteOnce,
Namespace=project-tiger,
should not define a storageClassName.
3. Create POD:
name=tata,
namespace=project-tiger,
volume=/tmp/tata-data,
image=httpd:2.4.41-alpine
1. Create PV: name=tata-pv, Capacity=2Gi, accessMode=ReadWriteOnce, hostPath=/srv/app-config-var , Remember: PV is not namespaced object.
Open kubernetes.io => Documentation => Search “pv hostPath”
Copy content like below from the website.
Copy |
Remove |
Our |
apiVersion: v1 kind: PersistentVolume metadata: name: task-pv-volume labels: type: local spec: storageClassName: manual capacity: storage: 10Gi accessModes: – ReadWriteOnce hostPath: path: “/mnt/data”
|
apiVersion: v1 kind: PersistentVolume metadata: name: tata-pv
spec: capacity: storage: 2Gi accessModes: – ReadWriteOnce hostPath: path: “/srv/app-config-var”
|
apiVersion: v1 kind: PersistentVolume metadata: name: tata-pv spec: capacity: storage: 2Gi accessModes: – ReadWriteOnce hostPath: path: “/srv/app-config-var”
|
kind: PersistentVolume
metadata:
name: tata-pv
spec:
capacity:
storage: 2Gi
accessModes:
– ReadWriteOnce
hostPath:
path: “/srv/app-config-var”
2. Create PVC: name=tata-pvc, Capacity=2Gi, accessMode=ReadWriteOnce, Namespace=project-tiger, should not define a storageClassName.
kubernetes.io => Documentation => Search “pvc accessModes”
Open the first link.
Copy the below content |
Remove the lines |
Our final file |
|
|
|
kind: PersistentVolumeClaim
metadata:
name: tata-pvc
namespace: project-tiger
spec:
accessModes:
– ReadWriteOnce
resources:
requests:
storage: 2Gi
3. Create pod: name=tata, namespace=project-tiger, volume=/tmp/tata-data, image=httpd:2.4.41-alpine
kubernetes.io => Documentation => Search “pod pvc”
Copy the below content |
Remove the lines |
Our final file |
|
|
|
apiVersion: v1
kind: Pod
metadata:
name: tata
namespace: project-tiger
spec:
volumes:
– name: data
persistentVolumeClaim:
claimName: tata-pvc
containers:
– name: task-pv-container
image: httpd:2.4.41-alpine
volumeMounts:
– mountPath: “/tmp/tata-data”
name: data
EOF
kubectl apply -f question7-pv.yaml
kubectl apply -f question7-pvc.yaml
kubectl apply -f question7-pod.yaml
NAME READY STATUS RESTARTS AGE
tata 1/1 Running 0 50s
bash-5.0# df -h
Filesystem Size Used Available Use% Mounted on
overlay 14.0G 8.3G 5.6G 60% /
tmpfs 64.0M 0 64.0M 0% /dev
/dev/sda2 14.0G 8.3G 5.6G 60% /tmp/tata-data
/dev/sda2 14.0G 8.3G 5.6G 60% /etc/hosts
/dev/sda2 14.0G 8.3G 5.6G 60% /dev/termination-log
/dev/sda2 14.0G 8.3G 5.6G 60% /etc/hostname
/dev/sda2 14.0G 8.3G 5.6G 60% /etc/resolv.conf
shm 64.0M 0 64.0M 0% /dev/shm
tmpfs 2.1G 12.0K 2.1G 0% /run/secrets/kubernetes.io/serviceaccount
tmpfs 1.1G 0 1.1G 0% /proc/acpi
tmpfs 64.0M 0 64.0M 0% /proc/kcore
tmpfs 64.0M 0 64.0M 0% /proc/keys
tmpfs 64.0M 0 64.0M 0% /proc/timer_list
tmpfs 1.1G 0 1.1G 0% /proc/scsi
tmpfs 1.1G 0 1.1G 0% /sys/firmware
bash-5.0#
total 0
From starting to end, please watch below video.
Question 8: Create a persistent volume with name app-motor, of capacity 2Gi and access mode ReadWriteMany. The type of volume is hostPath location is /srv/app-tata
Soloution:
kubectl config use-context ek8s
In this question, it is asked us to create only PV, thus we will only create PV.
Open URL : https://kubernetes.io –> Documentation –> Search => PV Accessmode ==> Open first link and search for “accessmode”
Copy the content link below:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0003
spec:
capacity:
storage: 5Gi
volumeMode: Filesystem
accessModes:
– ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
storageClassName: slow
mountOptions:
– hard
– nfsvers=4.1
nfs:
path: /tmp
server: 172.17.0.2
Now, modify the Yaml file as per the question
[root@master1 ~]# cat <<EOF>> question8-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: app-motor
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
– ReadWriteMany
hostPath:
path: “/srv/app-tata”
EOF
[root@master1 ~]# kubectl apply -f question8-pv.yaml
persistentvolume/app-motor created
[root@master1 ~]# kubectl get pv/app-motor
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
app-motor 2Gi RWX Retain Available manual 14m
Name: app-motor
Labels: type=local
Annotations: <none>
Finalizers: [kubernetes.io/pv-protection]
StorageClass: manual
Status: Available
Claim:
Reclaim Policy: Retain
Access Modes: RWX
VolumeMode: Filesystem
Capacity: 2Gi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /srv/app-tata
HostPathType:
Events: <none>
[root@master1 ~]#
If you want to learn hostPath volume then you may watch my Youtube video.
https://youtu.be/oRDBzoorybI