What is the main purpose of an init container in a Kubernetes Pod?
Think about tasks that must finish before the main app runs.
Init containers run before app containers to prepare the environment, like setting up files or waiting for services.
Given a Pod with one init container that completes successfully and one main container running, what will be the Pod's status?
kubectl get pod example-pod -o jsonpath='{.status.phase}'
Consider what happens after init containers finish.
Once all init containers finish successfully, the Pod status moves to Running as main containers start.
Which YAML snippet correctly defines an init container that runs a script before the main container?
apiVersion: v1
kind: Pod
metadata:
name: init-example
spec:
initContainers:
- name: init-script
image: busybox
command: ["sh", "-c", "echo Init task done"]
containers:
- name: main-app
image: nginxCheck the correct use of command as a list and proper placement of initContainers.
Option A correctly places initContainers before containers and uses command as a list of strings.
A Pod's init container keeps restarting and never completes. What is the most likely cause?
Think about what causes a container to restart repeatedly.
If the init container's command fails (non-zero exit), Kubernetes restarts it until success or failure limit.
Consider a Pod with three init containers named init1, init2, and init3. In what order will Kubernetes run these init containers?
Think about whether init containers run at the same time or one after another.
Kubernetes runs init containers one by one in the order they are listed in the Pod spec.