1. Introduction

Managing container images in Kubernetes deployments is crucial for maintaining the stability and efficiency of our applications. Being able to retrieve the current image of a Kubernetes deployment is an essential skill that enables us to track changes, ensure version control, and troubleshoot issues effectively.

In this tutorial, we’ll learn how to fetch the image of a Kubernetes deployment using various methods. This helps us gain valuable insights into the state of our deployments, enabling us to make informed decisions and maintain a reliable and up-to-date infrastructure.

2. Using kubectl jsonpath

In order to retrieve the current image of a Kubernetes deployment using the Kubernetes CLI (kubectl), we’ll use the kubectl get command. By specifying the deployment name and format option, we can obtain the desired information:

$ kubectl get deploy my-app -o jsonpath="{..image}"

The above command displays the image used by the my-app deployment. jsonpath is a template that helps in filtering the fields of a JSON.

We can also get the image of a pod using a similar command:

$ kubectl get pod myapp-79d545bd7c-c4w4l -o jsonpath="{..image}"

Here, we ran the kubectl get pod command followed by the pod name. Notably, the filter used is the same as above. This displays images used by all the containers running in the specified pod.

3. Using kubectl get deployments Command

The kubectl get deployments command is used to retrieve information about deployments in Kubernetes clusters. Furthermore, this command is useful for quickly checking the status and health of the deployments, verifying if they are running as expected, and monitoring their availability and readiness.

The kubectl get deployments -o wide command is an extension of the kubectl get deployments command in Kubernetes. It provides additional information about deployments in a wider output format:

$ kubectl get deployments -o wide
myapp     1/1     1            1           5m    python        python:3.8.10   app=python

By using the -o wide flag, we obtain additional details such as the containers, images and selector, providing a comprehensive overview of the deployments.

Moreover, we can also use the -A or –all-namespaces option to get a list of deployments across all the namespaces.

4. Conclusion

In this article, we learned different ways to find the image of a Kubernetes deployment. In conclusion, this helps us ensure that we deploy the correct image version, and maintain the stability and efficiency of our applications.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.