Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current image of kubernetes deployment

How can I use kubectl or the API to retrieve the current image for containers in a pod or deployment?

For example, in a deployment created with the below configuration, I want to retrieve the value eu.gcr.io/test0/brain:latest.

apiVersion: v1
   kind: Deployment
   metadata:
     name: flags
   spec:
     replicas: 6
     template:
       metadata:
      labels:
        app: flags
       spec:
         containers:
         - name: flags
           image: eu.gcr.io/test0/brain:latest
like image 908
Andy Hume Avatar asked Aug 22 '16 21:08

Andy Hume


People also ask

Does Kubernetes auto pull latest image?

If a tag is not specified in the manifest file, Kubernetes will automatically use the image tagged latest.


4 Answers

From kubectl 1.6 the -o wide option does this, so

kubectl get deployments -o wide

will show the current image in the output.

like image 58
Daniel Perez Avatar answered Nov 25 '22 22:11

Daniel Perez


You can use kubectl's jsonpath output option to achieve this:

kubectl get deployment flags -o=jsonpath='{$.spec.template.spec.containers[:1].image}'
like image 35
Pixel Elephant Avatar answered Nov 25 '22 23:11

Pixel Elephant


to get just the image uri for all pods (in all namespaces, for example):

kubectl get pods --all-namespaces -o jsonpath="{..image}"

(see https://kubernetes.io/docs/tasks/access-application-cluster/list-all-running-container-images/ for more detail)

like image 33
eversMcc Avatar answered Nov 25 '22 23:11

eversMcc


For a single deployment use this:

kubectl get deploy/deployment-name -o jsonpath="{..image}"

It can work for pod too

kubectl get pod/pod-name -o jsonpath="{..image}"
like image 22
Shalkam Avatar answered Nov 25 '22 22:11

Shalkam