0
0
Kubernetesdevops~20 mins

Init containers in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Init Container Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of Init Containers in Kubernetes

What is the main purpose of an init container in a Kubernetes Pod?

ATo monitor the health of the main containers continuously
BTo replace the main application containers
CTo provide a user interface for the Pod
DTo run setup tasks before the main containers start
Attempts:
2 left
💡 Hint

Think about tasks that must finish before the main app runs.

💻 Command Output
intermediate
2:00remaining
Output of Pod Status with Init Container

Given a Pod with one init container that completes successfully and one main container running, what will be the Pod's status?

Kubernetes
kubectl get pod example-pod -o jsonpath='{.status.phase}'
APending
BInit
CRunning
DSucceeded
Attempts:
2 left
💡 Hint

Consider what happens after init containers finish.

Configuration
advanced
3:00remaining
Correct Init Container YAML Configuration

Which YAML snippet correctly defines an init container that runs a script before the main container?

Kubernetes
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: nginx
A
initContainers:
- name: init-script
  image: busybox
  command: ["sh", "-c", "echo Init task done"]
containers:
- name: main-app
  image: nginx
B
containers:
- name: init-script
  image: busybox
  command: ["sh", "-c", "echo Init task done"]
initContainers:
- name: main-app
  image: nginx
C
initContainers:
- name: init-script
  image: busybox
  args: ["echo Init task done"]
containers:
- name: main-app
  image: nginx
D
initContainers:
- name: init-script
  image: busybox
  command: "echo Init task done"
containers:
- name: main-app
  image: nginx
Attempts:
2 left
💡 Hint

Check the correct use of command as a list and proper placement of initContainers.

Troubleshoot
advanced
2:30remaining
Troubleshooting Init Container Failure

A Pod's init container keeps restarting and never completes. What is the most likely cause?

AThe main container image is missing
BThe init container's command exits with a non-zero status
CThe Pod has no resource limits set
DThe Kubernetes node is out of disk space
Attempts:
2 left
💡 Hint

Think about what causes a container to restart repeatedly.

🔀 Workflow
expert
3:00remaining
Init Container Execution Order in Multi-Init Container Pod

Consider a Pod with three init containers named init1, init2, and init3. In what order will Kubernetes run these init containers?

Ainit1, then init2, then init3 sequentially
BAll three init containers run in parallel
Cinit3, then init2, then init1 sequentially
Dinit1 and init3 run in parallel, then init2 runs last
Attempts:
2 left
💡 Hint

Think about whether init containers run at the same time or one after another.