CKA · Question #44
Create a new PersistentVolumeClaim • Name: pv-volume • Class: csi-hostpath-sc • Capacity: 10Mi Create a new Pod which mounts the PersistentVolumeClaim as a volume: • Name: web-server • Image: nginx •
The test-taker must use kubectl commands in the provided web terminal to create a PersistentVolumeClaim and a Pod, then expand the PVC's capacity using kubectl edit or kubectl patch.
Question
Exhibit
Explanation
The test-taker must use kubectl commands in the provided web terminal to create a PersistentVolumeClaim and a Pod, then expand the PVC's capacity using kubectl edit or kubectl patch.
Approach. The correct approach involves a sequence of kubectl commands to achieve the stated objectives:
-
Create the PersistentVolumeClaim (PVC): First, define the PVC in a YAML file (e.g.,
pvc.yaml):apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pv-volume spec: storageClassName: csi-hostpath-sc accessModes: - ReadWriteOnce resources: requests: storage: 10MiThen apply it using
kubectl apply -f pvc.yaml(or create a file usingcat <<EOF > pvc.yamland then apply). -
Create the Pod: Next, define the Pod in a YAML file (e.g.,
pod.yaml) that mounts the PVC:apiVersion: v1 kind: Pod metadata: name: web-server spec: volumes: - name: pv-storage persistentVolumeClaim: claimName: pv-volume containers: - name: nginx image: nginx ports: - containerPort: 80 volumeMounts: - mountPath: "/usr/share/nginx/html" name: pv-storageThen apply it using
kubectl apply -f pod.yaml. -
Expand the PersistentVolumeClaim: Modify the PVC's storage capacity using either
kubectl editorkubectl patch:- Using
kubectl edit:kubectl edit pvc pv-volumeThis will open the PVC definition in a text editor (commonlyvi). Locate thespec.resources.requests.storagefield and change10Mito70Mi. Save and exit the editor (e.g., by typing:wqinviand pressing Enter). - Using
kubectl patch:kubectl patch pvc pv-volume -p '{"spec":{"resources":{"requests":{"storage":"70Mi"}}}}'
- Using
These steps correctly address all requirements: creating the PVC and Pod with specified parameters, mounting the volume, and performing the PVC expansion using the exact methods requested.
Common mistakes.
- common_mistake. Common mistakes include incorrect YAML syntax (indentation, field names), misspelling resource names or StorageClass, forgetting required fields like
accessModesin the PVC orclaimNamein the Pod's volume definition, or specifying an incorrectmountPath. When expanding the PVC, forgetting to save changes afterkubectl edit, or attempting to expand by directly modifying a local YAML file and runningkubectl applyagain (which may not always trigger expansion for storage capacity withoutkubectl editorpatch) would be incorrect. Not using the specifiedkubectl editorkubectl patchcommands for expansion would also be wrong, as the question explicitly mandates these methods. Failure to wait for the PVC to bind (if troubleshooting was necessary) could also lead to issues with the Pod starting correctly, although the question's focus is on the creation and modification commands.
Concept tested. This question tests fundamental Kubernetes concepts related to persistent storage: PersistentVolumeClaims (PVCs), StorageClasses, dynamic volume provisioning, mounting volumes to Pods, access modes (ReadWriteOnce), and volume expansion. It also assesses the test-taker's proficiency in using the kubectl command-line tool for resource creation (apply), modification (edit, patch), and YAML manifest authoring.
Reference. null
Topics
Community Discussion
No community discussion yet for this question.
