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:Creating a New Pod with the nginx Image
Next, create a new Pod that uses the nginx image by executing: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:Working with a Multi-Container Pod
Consider a Pod namedwebapp that contains two containers. To view the details of this multi-container Pod, run:
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 thewebapp Pod contains an image pull error, remove it by running:
Creating and Correcting a Redis Pod
Now, create a new Pod namedredis 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:redis.yaml. The file should resemble:
Step 2: Create the Redis Pod
Apply the YAML file to create the Pod:redis123 is invalid, the Pod enters an ErrImagePull state.
Step 3: Update the YAML File with the Correct Image
Edit theredis.yaml file to update the image name from redis123 to redis. The updated file should be:
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.