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?
Trap 1: Run the script as a sidecar container that shares the volume with…
Sidecar containers run concurrently, so the script may not finish before the main app starts.
Trap 2: Use a postStart lifecycle hook on the main container to run the…
postStart runs after the container starts, not before, and may not complete before the app begins.
Trap 3: Add a readiness probe to the main container that checks the shared…
Readiness probes check container readiness but do not guarantee init container completion.
- A
Run the script as a sidecar container that shares the volume with the main container.
Why wrong: Sidecar containers run concurrently, so the script may not finish before the main app starts.
- B
Use a postStart lifecycle hook on the main container to run the script.
Why wrong: postStart runs after the container starts, not before, and may not complete before the app begins.
- C
Define an init container with the script and mount the shared volume to both init and main containers.
Init containers run to completion before app containers start, and shared volumes persist data.
- D
Add a readiness probe to the main container that checks the shared volume.
Why wrong: Readiness probes check container readiness but do not guarantee init container completion.