Skip to main content
In this lab, you will learn how to work with Pods in Kubernetes using both imperative commands and declarative YAML configurations. The lab covers checking existing Pods, creating new Pods with different images, inspecting their details, troubleshooting common errors, and updating configurations to fix issues.

Listing Existing Pods

Start by listing the Pods in your default namespace. This step helps you verify that no unexpected Pods are running before you begin:
If no Pods are running, the output will look similar to:

Creating a New Pod with the nginx Image

Next, create a new Pod that uses the nginx image by executing:
The output should confirm the creation of the Pod:
Verify the creation by listing the Pods again:
You may see multiple Pods, especially if you have done previous exercises. For example:
Some Pods might still display “ContainerCreating” as they are in the process of being set up.

Inspecting Pod Details and Verifying the Image

To inspect the details of a specific Pod and verify which image is used, run:
For example, the detailed output may include:
In this excerpt, the image used is busybox. You can also use the wide output option to display node information:
The output might be:

Working with a Multi-Container Pod

Consider a Pod named webapp that contains two containers. To view the details of this multi-container Pod, run:
A sample excerpt from the description might show:
In this Pod, the nginx container is running normally, while the agentx container is in a waiting state due to an image pull error (ErrImagePull). When you list the Pods, observe that the READY column indicates the number of ready containers versus the total containers:
The ErrImagePull error indicates that Kubernetes failed to pull the image for the agentx container, likely because the image name is incorrect or the image does not exist on Docker Hub.

Deleting the Erroneous Web App Pod

Since the webapp Pod contains an image pull error, remove it by running:
You should see a deletion confirmation:

Creating and Correcting a Redis Pod

Now, create a new Pod named redis using an intentionally incorrect image name (redis123). This exercise demonstrates how to use declarative YAML and fix common errors.

Step 1: Create the YAML File

Generate the Pod definition using a dry run:
Redirect the output to a file named redis.yaml. The file should resemble:

Step 2: Create the Redis Pod

Apply the YAML file to create the Pod:
The expected output is:
Verify the Pod status:
The output may look like:
Since the image name redis123 is invalid, the Pod enters an ErrImagePull state.

Step 3: Update the YAML File with the Correct Image

Edit the redis.yaml file to update the image name from redis123 to redis. The updated file should be:
Apply the changes with:
You might see a warning indicating that the Pod is missing an annotation necessary for future apply operations. After updating, verify the status again:
An example output is:
The redis Pod is now running correctly thanks to the valid Docker image.

Conclusion

In this lab, you learned how to:
  • List existing Pods in a Kubernetes cluster.
  • Create new Pods using imperative commands with different images.
  • Inspect detailed information about Pods to verify configurations.
  • Troubleshoot common issues like image pull errors.
  • Use declarative YAML configurations to manage and update Pods.
Happy clustering and keep exploring more Kubernetes features!

Watch Video