Skip to main content
In this article, we will guide you through a series of tasks related to managing pods in Kubernetes. You will learn how to list existing pods, create pods with different images, inspect pod details, troubleshoot image pull errors, and update pod configurations using YAML definitions. ──────────────────────────────

Listing Existing Pods

To view the pods currently running in the default namespace, use the following command:
The output might look similar to this:
This output indicates that there are no pods running in the default namespace at the moment. ──────────────────────────────

Creating a New Pod with the Nginx Image

To create a new pod using the nginx image, run the command below. Make sure to specify both the pod name and the image:
After executing the command, you should see a confirmation message. Verify the pod list with:
In this example, along with the newly created nginx pod, there are several other pods present (assumed to be a total of four pods during this lab exercise). ──────────────────────────────

Inspecting Pod Details

To determine which container image a specific pod is using, inspect one of the pods in detail. For example, to inspect the pod named newpods-llstt, use:
A snippet of the output may resemble:
This output confirms that the container named busybox is using the busybox image. ──────────────────────────────

Determining Pod Node Placement

To view the nodes on which your pods are running, use the -o wide option:
Sample output:
Every pod in this output is running on the controlplane node. ──────────────────────────────

Checking Container Status Within a Pod

Consider a pod named webapp that contains two containers—one running nginx and another named agentx. To inspect the container details, use:
A relevant excerpt from the output might be:
The agentx container is currently waiting due to an image pull error—ErrImagePull indicates that Kubernetes was unable to locate the agentx Docker image on Docker Hub. The READY column in the kubectl get pods output will reflect this status (e.g., 1/2 indicating that only one out of two containers is ready).
When troubleshooting image pull errors, verifying the image name and tag is essential. Ensure the image exists on the container registry you are using.
──────────────────────────────

Deleting the Web App Pod

If you need to remove the webapp pod, execute the following command:
The output will confirm the pod deletion:
──────────────────────────────

Creating a New Pod with a Mistaken Redis Image

In this exercise, you will create a pod named redis using an intentional mistake in the image tag (redis123) to simulate an error scenario. Instead of using the kubectl run command directly, you will generate a YAML configuration file. First, generate the YAML definition with a dry-run command:
Redirect the output to a file named Redis.yaml. The generated YAML might appear as follows:
Create the pod using the YAML file:
The pod will be created but will enter an error state due to the incorrect image name.
The pod will not run correctly until you update the image to a valid one. This step is crucial for ensuring the application runs as expected.
──────────────────────────────

Correcting the Redis Pod Image

To resolve the error, update your YAML definition to use the correct image, redis. You can update the file directly and then apply your changes, or use the kubectl edit command. The image below illustrates the process of updating the Redis pod’s image:
A terminal interface with instructions to change a pod's image to "redis" and ensure it is in a running state.
After editing, the YAML should be updated as follows:
Apply the modified YAML with:
You might encounter a warning about the missing kubectl.kubernetes.io/last-applied-configuration annotation. The output will be similar to:
Confirm that the pod is now running by executing:
A sample output might look like this:
The updated redis pod now indicates that all containers are running and ready. ──────────────────────────────

Conclusion

In this lab solution, you learned how to:
  • List pods in the default namespace.
  • Create a pod using the kubectl run command.
  • Inspect pod details to verify container images and node assignment.
  • Troubleshoot image pull errors by diagnosing pod statuses (e.g., the agentx container).
  • Create and update a pod using a YAML configuration.
Thank you for following along, and happy Kubernetes learning!

Watch Video