Kubernetes CKA sample exam question 23 with answer

Question
Create a PersistentVolume, PersistentVolumeClaim and Pod with below specifications:

PV
Volume name: mypvlog
Storage: 100Mi
Access Modes: ReadWriteMany
Host Path: /pv/log
Reclaim Policy: Retain

PVC:
Volume Name: pv-claim-log
Storage: 50Mi
Access Modes: ReadWriteMany

Pod
Name: my-nginx-pod
Image name: nginx
Volume: PersistentVolumeClaim=pv-claim-log
Volume Mount: /log

Answer
Go to the Kubernetes Documentation page and search for PersistentVolume. Copy the template and adjust it in the following way:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mypvlog
spec:
  capacity:
    storage: 100Mi
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/pv/log"
Apply and check:
kubectl apply -f pv.yaml
kubectl get pv
Same for PVC - go to the Kubernetes Documentation page and search for PersistentVolumeClaim. Copy the template and adjust it in the following way:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-log
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 50Mi
Apply and check if volume is bound:
kubectl apply -f pvc.yaml
kubectl get pv
kubectl get pvc
For pod - the manifest is following:
apiVersion: v1
kind: Pod
metadata:
  name: my-nginx-pod
spec:
  volumes:
  - name: mypd
    persistentVolumeClaim:
      claimName: pv-claim-log
  containers:
  - name: mypod
    image: nginx
    volumeMounts:
    - mountPath: "/log"
      name: mypd
Apply and check"
kubectl apply -f po.yaml
kubectl get po
kubectl describe po my-nginx-pod