CKAD Multi-Container Pods and Init Containers 2 — Questions and Answers
Question 1: What type of volume is created when a pod starts, lives as long as the pod, and is deleted when the pod is removed?
- PersistentVolume
- emptyDir (Correct answer)
- hostPath
- configMap
Correct answer: emptyDir
An emptyDir volume is created empty when the pod is scheduled, shared among containers, and deleted when the pod is removed.
Question 2: An Init Container needs to clone a Git repo before the main app starts. Which volume type is best for sharing the cloned files?
- PersistentVolumeClaim
- emptyDir (Correct answer)
- hostPath
- nfs
Correct answer: emptyDir
An emptyDir volume is ideal for passing data from an init container to app containers since it's shared within the pod and cleaned up automatically.
Question 3: Which field in a pod spec lists init containers?
- spec.containers
- spec.initContainers (Correct answer)
- spec.setup
- spec.beforeContainers
Correct answer: spec.initContainers
Init containers are defined under 'spec.initContainers', separate from 'spec.containers' where app containers are listed.
Question 4: In the Sidecar pattern, which describes the relationship between the sidecar and main container?
- The sidecar replaces the main container on failure
- The sidecar enhances or extends the main container's functionality while running alongside it (Correct answer)
- The sidecar intercepts all incoming traffic before it reaches the main container
- The sidecar runs only during startup and exits
Correct answer: The sidecar enhances or extends the main container's functionality while running alongside it
A sidecar runs concurrently with the main container in the same pod, extending its capabilities (e.g., log shipping, proxying).
Question 5: What is a key difference between Init Containers and regular containers regarding running simultaneously?
- Init containers run in parallel with app containers
- Init containers run sequentially to completion before any app container starts (Correct answer)
- Init containers and app containers always run in parallel
- Init containers run after app containers have started
Correct answer: Init containers run sequentially to completion before any app container starts
Init containers run one at a time in order and must complete successfully before the pod's main containers are started.
Question 6: Which command shows the logs of a specific container named 'sidecar' in a multi-container pod named 'mypod'?
- kubectl logs mypod sidecar
- kubectl logs mypod --container=sidecar
- kubectl logs mypod -c sidecar
- Both B and C are correct (Correct answer)
Correct answer: Both B and C are correct
Both '--container=sidecar' and '-c sidecar' are valid flags to specify the container when retrieving logs from a multi-container pod.
What type of volume is created when a pod starts, lives as long as the pod, and is deleted when the pod is removed?