Reading the Kubernets documentation it looks to be possible to select a certain range of pods based on labels. I want to select all the pods on one node but I don't want to label each pod on their corresponding node.
Am I missing something from the documentation or is it just not possible to select by node?
If I do:
kubectl get pods \ --output=wide --namespace=$NS \ --server=$SERVER | head #=> NAME READY STATUS RESTARTS AGE NODE
Can any of these headers be used as selector? If yes, how to do it with kubectl
? How to do it with the API?
You can add the nodeSelector field to your Pod specification and specify the node labels you want the target node to have. Kubernetes only schedules the Pod onto nodes that have each of the labels you specify.
To find the cluster IP address of a Kubernetes pod, use the kubectl get pod command on your local machine, with the option -o wide . This option will list more information, including the node the pod resides on, and the pod's cluster IP. The IP column will contain the internal cluster IP address for each pod.
The containers in a Pod share an IP Address and port space, are always co-located and co-scheduled, and run in a shared context on the same Node.
As mentioned in the accepted answer the PR is now merged and you can get pods by node as follows:
kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=<node>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With