Home > Enterprise >  kubectl - How to retrieve values of default labels in kubernetes?
kubectl - How to retrieve values of default labels in kubernetes?

Time:10-20

As mentioned here: "Currently namespace, pod are default labels provided in the metrics."


kubectl -n mynamespace get pods --show-labels show the label values that are defined in deployment yaml for Kubernetes


Goal is to use default label(namespace & pod provided by kubernetes) values through Grafana dashboard's promQL, that prometheus monitor.

sum(container_memory_working_set_bytes{namespace="mynamespace",pod=~"unknown"}) by (pod)

How to view the values of default label pod using kubectl?

CodePudding user response:

According to the link that you shared, {namespace} and {pod} are default labels provided in the metrics, they are referring to the exposed metrics included in the kube-state-metrics (KSM) service.

kube-state-metrics (KSM) is a simple service that listens to the Kubernetes API server and generates metrics about the state of the objects. The exposed metrics are detailed in this document.

In the following links, you can find the related metric for Pods and namespace.

Speaking about the default labels for pods, you need to create a Pod label controller or indicate the label in the Pod Template.

If you don't explicitly specify labels for the controller, Kubernetes will use the pod template label as the default label for the controller itself. The pod selector will also default to pod template labels if unspecified.

If you want to know more about best practices for labels, please follow this link. If you want to know more about Labels and selector, follow this link. More about Pod Template here.

  • Related