Get Deployment annotation from a Kubernetes Pod
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).
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.
kubectl get pod POD_NAME -o jsonpath='{.metadata.annotations}'
As an alternative, you can leverage both using a kubectl selector to query all pods with label app=myapp
and jq to query and format the resulting json to get you the name and annotations for each of the pods
kubectl get po -l app=myapp -o=json | jq '[. | {pod: .items[].metadata}][] | {name: .pod.name, annotations: .pod.annotations}'