Get current image of kubernetes deployment
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Kubernetes, an open-source orchestration platform for managing containerized applications, simplifies the deployment, scaling, and operations of application containers. Often, it's vital for users to retrieve the current configuration, especially the image version, of a Kubernetes deployment. This task involves utilizing the Kubernetes Command-Line Tool (kubectl) to explore deployment manifests and descriptions.
Understanding Kubernetes Deployments
A Kubernetes deployment is a higher-level abstraction for managing stateless applications. It manages the creation and scaling of pods, the smallest deployable objects in Kubernetes, and ensures that the desired state specified in the deployment manifest is maintained at all times.
Deployment Manifests
The deployment manifest is a YAML or JSON file that configures the various properties of the deployment, including the definition of the container image. Here’s a snippet of a typical deployment manifest:
In the above YAML example, nginx:1.14.2 is the image currently used by the deployment.
Retrieving the Current Image
To get the current image of a Kubernetes deployment, follow these steps:
Using kubectl
kubectl is the command-line interface used to interact with Kubernetes clusters. It provides multiple ways to retrieve the current image from a deployment.
Method 1: Describing the Deployment
To retrieve detailed information about a deployment, including its current image, you can use the kubectl describe deployment command. This command outputs a comprehensive description of the deployment:
This command will display a broad overview of the deployment, including events, conditions, and the running image under the Containers: section like:
Method 2: Using kubectl get with JSONPath
For a more focused output, you can use the kubectl get command with JSONPath expressions, which allows you to extract specific information:
This command will directly output the image of the first container in the deployment:
Practical Considerations
- Automating Retrieval: You can integrate these commands into scripts to automate reporting or logging of container images.
- Monitoring Updates: Use these commands in CI/CD pipelines to verify the deployment images after updates.
- Security Practices: Regularly reviewing the images in use helps ensure that the deployments run the latest, most secure versions.
Troubleshooting Tips
While retrieving deployed images is straightforward, you may encounter some issues:
- Access Restrictions: Ensure you have sufficient permissions to access cluster resources. Use the
kubectl auth can-icommand to check:
- Path Changes: In complex manifests with multiple containers, adjust the JSONPath appropriately to target the correct container index.
Key Points Summary
| Command Summary | Description |
kubectl describe deployment <name> | Provides a comprehensive view of a deployment, including image. |
kubectl get deployment <name> -o=jsonpath='{.spec.template.spec.containers[:1].image}' | Fetches the current image of the first container directly. |
| Automation Potential | Automate image retrieval via scripts or CI/CD. |
| Permission Check | Use kubectl auth can-i to verify access rights. |
| Correct JSONPath Usage | Adjust JSONPath according to container structure. |
Conclusion
Retrieving the current image of a Kubernetes deployment is a key step in managing and verifying application states within a cluster. By effectively utilizing kubectl, administrators can ensure consistent and up-to-date information on their deployment components, facilitating robust and secure operations within Kubernetes environments.

