kubectl get nodes
The output will vary depending on your cluster. The example below is taken from a minikube cluster:
NAME STATUS ROLES AGE VERSION minikube Ready control-plane,master 42m v1.20.2
kubectl label nodes minikube shouldrun=here
Now we can create a pod that is scheduled on the node with the label
kubectl apply -f https://raw.githubusercontent.com/openshift-evangelists/kbe/main/specs/nodes/pod.yaml
-o wideflag, when retrieving pod information, will show the node on which the pod is running:
kubectl get pods --output=wide
In this case, the node is the same one that was labeled in the
label command above.
describesubcommand contains a wealth of information about the node (the example output below has been truncated for readability):
Name: minikube Roles: control-plane,master ... Addresses: InternalIP: 192.168.39.147 Hostname: minikube Capacity: cpu: 4 ephemeral-storage: 17784752Ki hugepages-2Mi: 0 memory: 11999700Ki pods: 110 ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal NodeHasSufficientMemory 47m (x7 over 47m) kubelet Node minikube status is now: NodeHasSufficientMemory Normal NodeHasNoDiskPressure 47m (x6 over 47m) kubelet Node minikube status is now: NodeHasNoDiskPressure Normal NodeHasSufficientPID 47m (x6 over 47m) kubelet Node minikube status is now: NodeHasSufficientPID Normal Starting 47m kubelet Starting kubelet. ...
Note that there are more sophisticated methods than shown above, such as using affinity, to assign pods to nodes.