CKAD Application Design and Build Practice Question
A team is deploying a microservice that requires initialization of a database schema before the main application starts. The init container must run a script that writes to a shared volume. Which configuration correctly ensures the init container completes before the main container runs?
⚠ Common exam trap
Candidates often confuse init containers with sidecar containers or lifecycle hooks, not realizing that only init containers guarantee sequential execution before main containers, while sidecars and hooks run concurrently or asynchronously.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Define an init container with the script and mount the shared volume to both init and main containers.
An init container runs to completion before any main container in the Pod starts, ensuring the database schema script finishes. By mounting the shared volume to both the init container and the main container, the script's output (e.g., schema files) is available to the main application when it launches.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Run the script as a sidecar container that shares the volume with the main container.
Why it's wrong here
A sidecar container runs concurrently with the main container for the entire pod lifetime, not as a one-shot prerequisite. Because Kubernetes does not sequence sidecar startup relative to other containers, the main application can launch before the sidecar's script completes, leaving the shared volume empty or partially populated. Therefore, a sidecar is unsuitable for tasks that must finish before the main process begins.
- ✗
Use a postStart lifecycle hook on the main container to run the script.
Why it's wrong here
postStart hooks execute after the container's main process is created, and Kubernetes runs them asynchronously without blocking the application's startup. The container may begin operating before the hook script finishes, and if the script fails, it is not automatically retried, potentially leaving the application in an inconsistent state. This makes postStart inappropriate for initialization that must complete before the app code runs.
- ✓
Define an init container with the script and mount the shared volume to both init and main containers.
Why this is correct
Init containers always run to completion before any application container in the pod is started, and each init container must exit with status 0. By mounting the same volume in both the init container and the main container, the script can write required files that the main container reads immediately upon startup. This guarantees the initialization is fully completed before the microservice process begins.
- ✗
Add a readiness probe to the main container that checks the shared volume.
Why it's wrong here
Readiness probes only control when a container receives traffic; they do not delay container startup or the execution of its entrypoint. The main container has already started by the time the probe begins, so missing initialization data could crash it even if the probe later succeeds. Probes are for load-balancing and rolling updates, not for ordering container startup.
Go deeper
Related to this question
About these practice questions
Courseiva writes every CKAD question from scratch — 160 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This CKAD practice question is part of Courseiva's free CNCF certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the CKAD exam.