1. Verify Existing Pods
First, examine the current pods running in your Kubernetes cluster by executing: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:3. Inspecting Pod Details
To inspect details about one of the newly created pods (for example,newpods-llstt), use:
busybox.
Determine Node Placement
To see which nodes are hosting your pods, run:controlplane node.
4. Working with a Multi-Container Pod (Web App)
Now consider a pod namedwebapp that includes two containers—one running the nginx image and the other using the agentx image. Check the status of the pods with:
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:
- The
nginxcontainer is in a Running state. - The
agentxcontainer is in a Waiting state with the reasonErrImagePull, 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 thewebapp pod has an error, remove it using:
6. Creating and Modifying a Redis Pod Using a YAML Definition
Next, you will create a pod namedredis 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:redis.yaml file looks like this:
redis pod is in an ErrImagePull state.
Updating the YAML to Correct the Image
To fix this error, edit theredis.yaml file to use the correct image name. Replace redis123 with redis:
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
READYcolumn. - Delete faulty pods.
- Define and modify pod configurations using YAML.