Kubernetes: list all pods and its nodes

I have 3 nodes, running all kinds of pods. I would like to have a list of nodes and pods, for an example:

NODE1 POD1 NODE1 POD2 NODE2 POD3 NODE3 POD4 

How can this please be achieved?

Thanks.

1

6 Answers

You can do that with custom columns:

kubectl get pod -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName --all-namespaces 

or just:

kubectl get pod -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name --all-namespaces 
5

kubectl has a simple yet useful extended output format that you can use like

kubectl get pod -o wide 

so while custom formats provided in other answers are good, this might be a handy shortcut.

3

You can use kubectl get pods --all-namespaces to list all the pods from all namespaces and kubectl get nodes for listing all nodes.

2

The following command does more or less what you wanted. However, it's more of a jq trick than kubectl trick:

kubectl get pod --all-namespaces -o json | jq '.items[] | .spec.nodeName + " " + .status.podIP'

3

Not exactly as you wanted cause it describe much more, but you can use

kubectl describe nodes

it will expose each pod per node in the cluster with the following info

Namespace | Name | CPU Requests | CPU Limits | Memory Requests | Memory Limits

1

This gets you: "nodeName namespace pod" across the cluster:

kubectl get pods --all-namespaces --output 'jsonpath={range .items[*]}{.spec.nodeName}{" "}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like