Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Kubernetes search terms

I have problems finding the values used for selecting or displaying objects in kubernetes. I feel like I'm not using the kubernetes docs correctly or these are linked with a command I haven't learned yet.

Examples:

  1. Find all the pods on a certain node? How do you know it's in spec.nodeName

    kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>

  2. Get all Pods in a running state? How do you know this value is stored in status.phase

    kubectl get pods --field-selector status.phase=Running

  3. Get all pods but only listing the name, How do you know it called metadata.name

    kubectl get pods -o custom-columns:POD:metadata.name

like image 507
craig goble Avatar asked Jan 21 '26 20:01

craig goble


2 Answers

Each resource in Kubernetes is described by some specification. You can find the detailed spec for the resources in the documentation, for example here https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/. If you navigate to the Pod definition (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#pod-v1-core) you will see all the properties of the Pod type with their underlying types.

For example, your first point, reading the PodSpec (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#podspec-v1-core) you can see that the nodeName property holds the name of a node that should be used to schedule the pod.

Same documentation can be reviewed from the kubectl command. To get the documentation for PodSpec you can just type kubectl explain pod.spec

like image 60
krizas Avatar answered Jan 23 '26 17:01

krizas


You can go through the documentation of kubectl command line to understand how to user it. The below link give you exactly the same.

https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors/

Meanwhile the third command should be modified as below to get the output as the only the name of the pod.

kubectl get pods  --output=custom-columns=NAME:metadata.name
like image 21
Wasim Ansari Avatar answered Jan 23 '26 18:01

Wasim Ansari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!