Skip to main content
In this lesson, we address several tasks related to init containers. We demonstrate how to identify pods with init containers, update a pod configuration to use a new init container, and fix an issue causing a CrashLoopBackOff in one pod. Follow the steps below for a comprehensive guide.

Identifying the Pod with an Init Container

First, list all the pods with:
Example output:
We have three pods: red, green, and blue. To determine which pod includes an init container, execute:

Red Pod Analysis

When you inspect the red pod, you see an init container section alongside the main container. Here’s a snippet from the red pod’s description:
Although an init container is shown in the red pod, further analysis of other pods is required.

Green Pod Analysis

The green pod does not include an init container. Its configuration is similar to the following:
Since it lacks an init container, proceed to the next pod.

Blue Pod Analysis

The blue pod includes a well-defined init container. Its description shows:
Thus, the blue pod is the one with an init container using the “busybox” image. The container ran a “sleep 5” command, and its state is confirmed as Terminated (Reason: Completed).

Question 1 Recap

  • Pod with an init container: blue
  • Init container’s image: busybox
  • Init container’s state: Terminated (Reason: Completed)

Analyzing the Purple Pod

A new application named purple was deployed. Its configuration includes multiple init containers. To examine it, run:
This outputs a snippet similar to:
The purple pod has two init containers:
  • warm-up-1: sleeps for 600 seconds (10 minutes)
  • warm-up-2: sleeps for 1200 seconds (20 minutes)
They run sequentially, so the main container only starts after both complete. The total wait time before availability is 1800 seconds (30 minutes).

Updating a Pod to Use an Init Container

The next task is to update the “red” pod to incorporate an init container. The new init container uses the busybox image to sleep for 20 seconds instead of a longer duration.

Steps to Update the “red” Pod

  1. Export the current configuration:
  2. Delete the existing red pod:
  3. Edit red.yaml to add the init container. Below is the updated configuration:
  4. Apply the new configuration:
After applying, verify that the red pod is recreated and the new init container executes the “sleep 20” command before starting the main container.

Fixing the Issue with the Orange Pod

The orange pod is encountering an issue with its init container, as it is stuck in a crash loop. Listing pods shows:
Output example:
Describing the orange pod reveals an error in the init container command:
The typo “sleeep” (with an extra “e”) causes the container to fail (Exit Code: 127) and triggers a CrashLoopBackOff.
Ensure that command spelling is correct, as errors like this prevent the container from starting and lead to repeated restarts.

Steps to Fix the Orange Pod

  1. Export the orange pod configuration:
  2. Delete the existing orange pod:
  3. Edit orange.yaml to correct the command in the init container. The updated configuration should be:
  4. Apply the corrected configuration:
Once updated, the orange pod should operate normally without entering a crash loop.

Conclusion

This guide provided a step-by-step walkthrough of:
  • Identifying pods with init containers (examining red, green, and blue pods)
  • Reviewing key details such as image names, commands, and the state of init containers
  • Updating a pod’s configuration (red pod) to replace a lengthy sleep command in its init container with a shorter one
  • Diagnosing and fixing a typo in the orange pod that caused a CrashLoopBackOff
Following these steps will help you efficiently manage and troubleshoot init containers in your Kubernetes environment.

Additional Resources

Watch Video