Do you have a running Kubernetes cluster and trying to list all the Pods running in a specific worker / control plane node?. A Pod is basically the smallest viable object of the Kubernetes ecosystem. A Pod can comprise of one or more containers in it.
List nodes in your cluster.
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
master01 Ready control-plane 244d v1.26.5
master02 Ready control-plane 244d v1.26.5
master03 Ready control-plane 237d v1.26.5
node01 Ready <none> 244d v1.26.5
node02 Ready <none> 244d v1.26.5
node03 Ready <none> 244d v1.26.5
node04 Ready <none> 237d v1.26.5
node05 Ready <none> 237d v1.26.5
node06 Ready <none> 22d v1.26.5
node07 Ready <none> 7d11h v1.26.5
We’ll consider using different command options that you can use to list all running pods in a kubernetes node.
List running Pods in Kubernetes node using kubectl describe
You can use kubectl describe pods
command to get detailed information about all pods running in a Kubernetes node.
$ kubectl describe node master01
Name: master01
Roles: control-plane
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
kubernetes.io/hostname=master01
kubernetes.io/os=linux
node-role.kubernetes.io/control-plane=
node.kubernetes.io/exclude-from-external-load-balancers=
Annotations: csi.volume.kubernetes.io/nodeid: {"rook-ceph.cephfs.csi.ceph.com":"master01","rook-ceph.rbd.csi.ceph.com":"master01"}
kubeadm.alpha.kubernetes.io/cri-socket: unix:///var/run/containerd/containerd.sock
node.alpha.kubernetes.io/ttl: 0
projectcalico.org/IPv4Address: 192.168.1.10/24
projectcalico.org/IPv4VXLANTunnelAddr: 10.233.106.128
volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp: Wed, 14 Dec 2022 03:11:08 +0300
Taints: <none>
Unschedulable: false
Lease:
HolderIdentity: master01
AcquireTime: <unset>
RenewTime: Wed, 16 Aug 2023 02:13:45 +0300
Conditions:
Type Status LastHeartbeatTime LastTransitionTime Reason Message
---- ------ ----------------- ------------------ ------ -------
NetworkUnavailable False Sun, 13 Aug 2023 11:11:04 +0300 Sun, 13 Aug 2023 11:11:04 +0300 CalicoIsUp Calico is running on this node
MemoryPressure False Wed, 16 Aug 2023 02:13:40 +0300 Thu, 15 Jun 2023 19:34:25 +0300 KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Wed, 16 Aug 2023 02:13:40 +0300 Thu, 15 Jun 2023 19:34:25 +0300 KubeletHasNoDiskPressure kubelet has no disk pressure
PIDPressure False Wed, 16 Aug 2023 02:13:40 +0300 Thu, 15 Jun 2023 19:34:25 +0300 KubeletHasSufficientPID kubelet has sufficient PID available
Ready True Wed, 16 Aug 2023 02:13:40 +0300 Wed, 09 Aug 2023 18:29:43 +0300 KubeletReady kubelet is posting ready status
Addresses:
InternalIP: 192.168.1.10
Hostname: master01
Capacity:
cpu: 2
ephemeral-storage: 51907148Ki
hugepages-2Mi: 0
memory: 8141268Ki
pods: 110
Allocatable:
cpu: 2
ephemeral-storage: 47837627518
hugepages-2Mi: 0
memory: 8038868Ki
pods: 110
System Info:
Machine ID: 461bc0cf54024b6b97cc2dc175c4dd5d
System UUID: 461bc0cf-5402-4b6b-97cc-2dc175c4dd5d
Boot ID: 93f10bf0-0c4f-4aea-9107-cbac4c47f1e5
Kernel Version: 5.15.122-flatcar
OS Image: Flatcar Container Linux by Kinvolk 3510.2.6 (Oklo)
Operating System: linux
Architecture: amd64
Container Runtime Version: containerd://1.7.1
Kubelet Version: v1.26.5
Kube-Proxy Version: v1.26.5
PodCIDR: 10.233.64.0/24
PodCIDRs: 10.233.64.0/24
Non-terminated Pods: (12 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits Age
--------- ---- ------------ ---------- --------------- ------------- ---
kube-system calico-node-vnb8v 150m (7%) 300m (15%) 64M (0%) 500M (6%) 6d7h
kube-system coredns-645b46f4b6-g6r8l 100m (5%) 0 (0%) 70Mi (0%) 300Mi (3%) 12d
kube-system dns-autoscaler-7f7b458498-ns84m 20m (1%) 0 (0%) 10Mi (0%) 0 (0%) 12d
kube-system kube-apiserver-master01 250m (12%) 0 (0%) 0 (0%) 0 (0%) 12d
kube-system kube-controller-manager-master01 200m (10%) 0 (0%) 0 (0%) 0 (0%) 12d
kube-system kube-proxy-9jbfk 0 (0%) 0 (0%) 0 (0%) 0 (0%) 6d7h
kube-system kube-scheduler-master01 100m (5%) 0 (0%) 0 (0%) 0 (0%) 12d
kube-system nodelocaldns-wjlzb 100m (5%) 0 (0%) 70Mi (0%) 200Mi (2%) 6d7h
metallb-system speaker-6fpws 0 (0%) 0 (0%) 0 (0%) 0 (0%) 6d7h
monitoring node-exporter-6qb57 112m (5%) 270m (13%) 200Mi (2%) 220Mi (2%) 6d7h
rook-ceph csi-cephfsplugin-tsk2q 0 (0%) 0 (0%) 0 (0%) 0 (0%) 6d7h
rook-ceph csi-rbdplugin-8cxxt 0 (0%) 0 (0%) 0 (0%) 0 (0%) 6d7h
Allocated resources:
(Total limits may be over 100 percent, i.e., overcommitted.)
Resource Requests Limits
-------- -------- ------
cpu 1032m (51%) 570m (28%)
memory 431001600 (5%) 1254974720 (15%)
ephemeral-storage 0 (0%) 0 (0%)
hugepages-2Mi 0 (0%) 0 (0%)
Events: <none>
The commands executed will show all non-terminated pods running on a node master01. Other information such as resource usage, system information, node role, labels, annotations, e.t.c.
List running Pods in Kubernetes node using filter
Another option is to list Pods running in all namespaces and filter using node’s name.
$ kubectl get pods -o wide --all-namespaces | grep master01
kube-system calico-node-vnb8v 1/1 Running 3 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system coredns-645b46f4b6-g6r8l 1/1 Running 6 (2d15h ago) 12d 10.233.106.174 master01 <none> <none>
kube-system dns-autoscaler-7f7b458498-ns84m 1/1 Running 6 (2d15h ago) 12d 10.233.106.172 master01 <none> <none>
kube-system kube-apiserver-master01 1/1 Running 11 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-controller-manager-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-proxy-9jbfk 1/1 Running 2 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system kube-scheduler-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system nodelocaldns-wjlzb 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
metallb-system speaker-6fpws 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
monitoring node-exporter-6qb57 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-cephfsplugin-tsk2q 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-rbdplugin-8cxxt 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph rook-ceph-osd-prepare-master01-26rfg 0/1 Completed 0 6h53m 10.233.106.181 master01 <none> <none>
We can also use --field-selector
command option.
$ kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=master01
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system calico-node-vnb8v 1/1 Running 3 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system coredns-645b46f4b6-g6r8l 1/1 Running 6 (2d15h ago) 12d 10.233.106.174 master01 <none> <none>
kube-system dns-autoscaler-7f7b458498-ns84m 1/1 Running 6 (2d15h ago) 12d 10.233.106.172 master01 <none> <none>
kube-system kube-apiserver-master01 1/1 Running 11 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-controller-manager-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-proxy-9jbfk 1/1 Running 2 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system kube-scheduler-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system nodelocaldns-wjlzb 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
metallb-system speaker-6fpws 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
monitoring node-exporter-6qb57 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-cephfsplugin-tsk2q 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-rbdplugin-8cxxt 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph rook-ceph-osd-prepare-master01-26rfg 0/1 Completed 0 6h57m 10.233.106.181 master01 <none> <none>
Using --field-selector spec.nodeName=
option can also filter pods. For example, to list all pods running on master01, we can run the commands below.
$ kubectl get pods -A --field-selector spec.nodeName=master01 -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kube-system calico-node-vnb8v 1/1 Running 3 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system coredns-645b46f4b6-g6r8l 1/1 Running 6 (2d15h ago) 12d 10.233.106.174 master01 <none> <none>
kube-system dns-autoscaler-7f7b458498-ns84m 1/1 Running 6 (2d15h ago) 12d 10.233.106.172 master01 <none> <none>
kube-system kube-apiserver-master01 1/1 Running 11 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-controller-manager-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system kube-proxy-9jbfk 1/1 Running 2 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
kube-system kube-scheduler-master01 1/1 Running 6 (2d15h ago) 12d 192.168.1.10 master01 <none> <none>
kube-system nodelocaldns-wjlzb 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
metallb-system speaker-6fpws 1/1 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
monitoring node-exporter-6qb57 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-cephfsplugin-tsk2q 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph csi-rbdplugin-8cxxt 2/2 Running 4 (2d15h ago) 6d8h 192.168.1.10 master01 <none> <none>
rook-ceph rook-ceph-osd-prepare-master01-26rfg 0/1 Completed 0 7h4m 10.233.106.181 master01 <none> <none>
We’re using the -o wide
flag to show additional information like the node’s name and namespace for each pod.
Conclusion
In this article, we share the commands that enables you to retrieve information about all pods and the nodes they are running on. By using filters we can pinpoint a specific node.