Get Deployment annotation from a Kubernetes Pod

kubectl get annotations
kubectl delete deployment
kubectl get pod logs
kubernetes deployment pod annotations
kubernetes annotations
kubectl delete pod
kubernetes annotations vs labels
kubectl restart 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.

Deployments, A Deployment provides declarative updates for PodsA Pod represents a set of running the command executed in the resource annotation kubernetes.io/ change-cause . Run kubectl get deployments to check if the Deployment was created. 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).

kubectl get pod POD_NAME -o jsonpath='{.metadata.annotations}'

kubectl Cheat Sheet, Users may want to define a common set of labels or annotations for all the Input: The kustomization.yaml and deployment.yaml files Labeling Workload Resources makes it simpler to query Pods - e.g. for the purpose of getting their logs. A Deployment provides declarative updates for Pods and ReplicaSets. You describe a desired state in a Deployment, and the Deployment ControllerA control loop that watches the shared state of the cluster through the apiserver and makes changes attempting to move the current state towards the desired state. changes the actual state to the desired state at a controlled rate. You can define

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.

Labels and Annotations � The Kubectl Book, It has been a long time but here is what I do to get a specific annotation : kubectl get ing test -o� and we can see our annotation! $ kubectl describe pod kolide-fleet-fleet-6fbd759d9d-plnzv Name: kolide-fleet-fleet-6fbd759d9d-plnzv Namespace: default Node: minikube/192.168.99.100 Start Time: Fri

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"}'

Get Deployment annotation from a Kubernetes Pod, If the same annotation is set multiple times, only the last value will be applied kubectl annotate pods foo description='my frontend' # Update a pod identified by � Both Pod and Deployment are full-fledged objects in the Kubernetes API. Deployment manages creating Pods by means of ReplicaSets. What it boils down to is that Deployment will create Pods with spec taken from the template. It is rather unlikely that you will ever need to create Pods directly for a production use-case.

kubectl annotate, kubectl get pods To find out why the nginx-deployment-1370807587-fz9sd pod is not running, we can use� Progressing Deployment. Kubernetes marks a Deployment as progressing when one of the following tasks is performed: The Deployment creates a new ReplicaSet. The Deployment is scaling up its newest ReplicaSet. The Deployment is scaling down its older ReplicaSet(s). New Pods become ready or available (ready for at least MinReadySeconds).

Application Introspection and Debugging, Kubernetes full pod name: Full name of the pod the container belongs to. Kubernetes namespace: Namespace� Here are some examples of information that could be recorded in annotations: Fields managed by a declarative configuration layer. Attaching these fields as annotations distinguishes them from default values set by clients or servers, and from auto-generated fields and fields set by auto-sizing or auto-scaling systems.

Organize Kubernetes deployments by tags, kubernetes_namespace is the Kubernetes namespace of the pod the metric comes from. between metrics from different pods of the same Deployment or DaemonSet. Annotations on pods allow a fine control of the scraping process:. Note that kubectl run creates a deployment, so in order to get rid of the pod you have to execute kubectl delete deployment sise. Using configuration file. You can also create a pod from a configuration file. In this case the pod is running the already known simpleservice image from above along with a generic CentOS container:

Comments
  • Please provide some explanation along with the code.