Get Deployment annotation from a Kubernetes Pod

5/1/2018

Each Kubernetes deployment gets this annotation:

$ kubectl describe deployment/myapp
Name:                   myapp
Namespace:              default
CreationTimestamp:      Sat, 24 Mar 2018 23:27:42 +0100
Labels:                 app=myapp
Annotations:            deployment.kubernetes.io/revision=5

Is there a way to read that annotation (deployment.kubernetes.io/revision) from a pod that belongs to the deployment?

I tried Downward API, but that only allows to get annotations of the pod itself (not of its deployment).

-- Kir
kubernetes

4 Answers

5/2/2018

Yes you can get the annotation from a pod using below command:

kubectl describe pod your_podname

and you will find Annotations section with all annotation for pod.

-- Nick Rak
Source: StackOverflow

12/10/2019

It has been a long time but here is what I do to get a specific annotation :

kubectl get ing test -o jsonpath='{.metadata.annotations.kubernetes\.io/ingress\.class}'

So for you it would be :

kubectl get deploy myapp -o jsonpath='{.metadata.annotations.deployment\.kubernetes\.io/revision}'

I hope it helps.

-- KrustyHack
Source: StackOverflow

11/11/2019
kubectl get pod POD_NAME -o jsonpath='{.metadata.annotations}'
-- StanislavKo
Source: StackOverflow

7/3/2019

to get only the annotations section of the pod you can use

kubectl describe pod YOUR_POD_NAME | get -i 'annotations'

you can also use jsonPath like

kubectl describe pod YOUR_POD_NAME -o jsonpath='{.metadata.annotations}{"\n"}'
-- jihed zaoueli
Source: StackOverflow