How to Use a Sidecar Container to Collect Redis Logs in Kubernetes
You are given a Kubernetes Pod manifest at storage.yaml. The manifest contains configuration errors that prevent the Pod from being deployed successfully.
storage.yaml manifest:
apiVersion: v1
kind: Pod
metadata:
name: storage-pod
spec:
containers:
- name: storage-container
image: nginx
volumeMounts:
- name: temp-storage
mountPath: /app/temp
volumes:
- name: temp-storage
emptyDir: {}Your task is to inspect and troubleshoot, correct all configuration errors, and deploy the Pod in the namespace.
The Pod must:
- Be named
storage-pod. - Use the
nginxcontainer image. - Be in the Running state.
- Define an
emptyDirvolume namedtemp-storage. - Mount
temp-storageat/app/tempinside the container.
After deploying the Pod, verify that the volume is correctly defined and mounted at /app/temp.
Identify the Errors
The provided manifest has 4 issues
Compare the two manifests
Line 1: Incorrect apiVersion
The manifest uses an invalid API version, v1/beta.For a Kubernetes Pod, the correct API version is v1.
Line 2: Incorrect kind
The manifest uses an incorrect resource kind, pod. Kubernetes resource kinds are case-sensitive, so the correct value is Pod.
Line 9: Incorrect volumeMounts field
The manifest uses an incorrect field name, VolumeMounts. The correct field is volumeMounts, with a lowercase v and m.
Line 12: Incorrect volumes field
The manifest uses an incorrect field name, Volumes. The correct field is volumes, with a lowercase v.
Deploy the Pod
Apply the corrected manifest:
$ kubectl apply -f storage.yaml
pod/storage-pod createdVerify the Pod Status
Check the Pod:
$ kubectl get pod storage-pod
NAME READY STATUS RESTARTS AGE
storage-pod 1/1 Running 0 10sVerify the Volume, Mount
Check the /app/temp directory inside the container:
$ kubectl exec -it storage-pod -- ls /app/tempThe directory should exist because the emptyDir volume is mounted there.
You can also verify the mount configuration with:
kubectl describe pod storage-podLook for the Mounts section:
Mounts:
/app/temp from temp-storageAnd the Volumes section should show:
Volumes:
temp-storage:
Type: EmptyDirWhy Does the Volume Name Matter?
The volume name defined under volumes must match the name referenced under volumeMounts. For example, if volumeMounts usesname: temp-storage, the volumes section must define a volume with the same name.
This matching name allows Kubernetes to associate the container's mount path with the correct volume. If the names do not match, the Pod configuration is invalid and Kubernetes cannot mount the volume.
What Is a Kubernetes emptyDir Volume?
An emptyDir volume is a temporary volume created when a Pod is assigned to a node. It starts empty and can be shared by containers within the same Pod to store temporary data.
For example, volumes: - name: temp-storage emptyDir: {} creates an emptyDir volume named temp-storage. The data remains available for the lifetime of the Pod and is deleted when the Pod is removed from the node.
CKA Exam Tips
These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.
Tip 1: Check API versions
When a manifest fails, first check whether the apiVersion is correct for the resource. For a Pod, use apiVersion: v1.
Tip 2: Kubernetes field names are case-sensitive
These are different: volumeMounts and VolumeMounts. Kubernetes field names are case-sensitive, so always use the exact field name.
Tip 3: Check indentation
Kubernetes YAML is indentation-sensitive. The volumes field belongs directly under spec, not inside the container definition.
Tip 4: Match volume names
Always use the same volume name in both volumeMounts and volumes. Here, both should use temp-storage.
Tip 5: Verify instead of assuming
After applying the manifest, don't stop at kubectl apply. Verify that the Pod is running with kubectl get pod storage-pod, then confirm the volume mount using kubectl describe pod storage-pod or kubectl exec -it storage-pod -- ls /app/temp.