This article provides a hands-on lab for understanding Kubernetes pods, including creation, inspection, and configuration using YAML.
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.
To inspect details about one of the newly created pods (for example, newpods-llstt), use:
Copy
Ask AI
kubectl describe pod newpods-llstt
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:
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:
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:
Copy
Ask AI
kubectl describe pod webapp
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.
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.
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:
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!