Skip to main content
In this lesson, you’ll explore a hands-on lab that deepens your understanding of Kubernetes pods. We’ll start by checking existing pods, create new ones with various images, inspect pod details, and adjust a pod configuration using YAML.

1. Verify Existing Pods

First, examine the current pods running in your Kubernetes cluster by executing:
You might see an output similar to this:
This command checks pods in the default namespace. In future lessons, we’ll dive deeper into namespaces and how they manage resources.

2. Creating a Pod with the Nginx Image

To create a new pod using the Nginx image, use the following command:
The pod creation is confirmed in the output:
After creating the pod, run the command again to see all current pods:
You might see a list similar to this:
Here, several pods have been created and will be examined further.

3. Inspecting Pod Details

To inspect details about one of the newly created pods (for example, newpods-llstt), use:
This command outputs extensive information such as start time, node assignment, labels, and container details. In the section under “Containers,” you should see an entry like:
The above confirms that the image used in the pod is busybox.

Determine Node Placement

To see which nodes are hosting your pods, run:
Sample output:
All listed pods are running on the controlplane node.

4. Working with a Multi-Container Pod (Web App)

Now consider a pod named webapp that includes two containers—one running the nginx image and the other using the agentx image. Check the status of the pods with:
You may observe output like the following:
The READY column uses an X/Y format, where X represents the number of containers ready, and Y is the total containers in the pod. Here, the webapp pod shows that while one container (nginx) is running, the second container (agentx) is not, due to an image pull error. To further inspect the webapp pod and diagnose the issue, run:
You’ll notice that:
  • The nginx container is in a Running state.
  • The agentx container is in a Waiting state with the reason ErrImagePull, indicating that the image “agentx” could not be pulled from Docker Hub.
The error indicates that the Docker image agentx does not exist or cannot be found on Docker Hub. Verify the image name before redeploying.

5. Deleting the Faulty Web App Pod

Since the webapp pod has an error, remove it using:
The standard output should confirm deletion:

6. Creating and Modifying a Redis Pod Using a YAML Definition

Next, you will create a pod named redis using an intentionally incorrect image (redis123) to simulate an error scenario. Although you can use kubectl run to create a pod, it’s recommended to define it with a YAML file for better control and maintainability.

Generating and Applying a YAML File

First, generate the YAML definition using a dry run:
The generated redis.yaml file looks like this:
Create the pod from the YAML file:
Check the pod status:
Expected output is similar to:
Because the image name is incorrect, the redis pod is in an ErrImagePull state.

Updating the YAML to Correct the Image

To fix this error, edit the redis.yaml file to use the correct image name. Replace redis123 with redis:
Apply the updated configuration:
You might see a warning regarding a missing annotation, which is normal when applying changes to imperatively created resources. Finally, verify that the pod is running:
An expected output would be:
This confirms that the corrected pod is now in a running state.

Conclusion

In this lab, you learned how to:
  • Verify the current pod count.
  • Create new pods using different images.
  • Inspect detailed pod configurations with kubectl describe.
  • Understand the significance of the READY column.
  • Delete faulty pods.
  • Define and modify pod configurations using YAML.
These practical exercises provide a solid foundation for working with pods in Kubernetes. Happy learning and explore further to master Kubernetes operations!

Watch Video