Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes API - gets Pods on specific nodes

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?

like image 468
Regnoult Avatar asked Aug 30 '16 15:08

Regnoult


People also ask

How do you force a pod to run on a specific node?

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.

How do you check which pods are running on which nodes?

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.

Do all containers in a pod run on the same node?

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.


1 Answers

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> 
like image 97
Kristofer Avatar answered Sep 21 '22 21:09

Kristofer