List All Pods and Nodes in Kubernetes
In this quick Kubernetes tutorial, learn about getting pods and nodes information.
In Kubernetes, managing and monitoring your cluster often involves interacting with the resources it manages, particularly Pods and Nodes. Pods are the smallest deployable units in Kubernetes, consisting of one or more containers that share storage and network resources. Nodes, on the other hand, are the worker machines (physical or virtual) where Pods are deployed.
This guide will walk you through the commands to list all Pods and Nodes in a Kubernetes cluster and briefly cover how to get detailed information about a specific Pod.
Listing All Pods
Pods are a critical resource in Kubernetes, representing the deployment of your application containers.
To list all Pods in your cluster, you can use the kubectl get pods
command.
1. List Pods in the Default Namespace
By default, Kubernetes organizes resources into namespaces. If you don't specify a namespace, kubectl assumes the default namespace.
kubectl get pods
This command lists all Pods in the default namespace. The output will include the Pod's name, ready status, status, restarts, and age.
NAME READY STATUS RESTARTS AGE
nginx-deployment-54f57cf6b7-x9t4x 1/1 Running 0 5m
nginx-deployment-54f57cf6b7-z8v4j 1/1 Running 0 5m
2. List Pods in All Namespaces
To get a comprehensive view of all Pods across all namespaces, use the --all-namespaces
or -A
flag:
kubectl get pods --all-namespaces
This command is particularly useful for administrators who need to monitor the entire cluster's state.
NAMESPACE NAME READY STATUS RESTARTS AGE
default nginx-deployment-54f57cf6b7-x9t4x 1/1 Running 0 5m
default nginx-deployment-54f57cf6b7-z8v4j 1/1 Running 0 5m
kube-system coredns-558bd4d5db-h7v5n 1/1 Running 0 15d
kube-system etcd-minikube 1/1 Running 0 15d
3. List Pods with Detailed Information
To get more detailed information about each Pod, including the node it is running on and the IP addresses, use the -o wide
option:
kubectl get pods -o wide
Output.
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deployment-54f57cf6b7-x9t4x 1/1 Running 0 5m 172.17.0.4 minikube <none> <none>
nginx-deployment-54f57cf6b7-z8v4j 1/1 Running 0 5m 172.17.0.5 minikube <none> <none>
4. Filtering Pods by Labels
Labels are key-value pairs attached to Kubernetes objects. You can filter Pods based on these labels using the -l
flag:
kubectl get pods -l app=my-app
This command lists all Pods with the label app=my-app
.
NAME READY STATUS RESTARTS AGE
my-app-7f94987d5c-n8qlm 1/1 Running 0 10m
my-app-7f94987d5c-x9c8f 1/1 Running 0 10m
5. Getting Details of a Specific Pod
Sometimes, you need to delve deeper into a specific Pod's status and configuration. The kubectl describe pod command provides detailed information about a particular Pod, including events, conditions, and container statuses.
kubectl describe pod nginx-pod
This will gives you detail information about nginx-pod
. This command is useful for troubleshooting and understanding the Pod's lifecycle.
Name: nginx-pod
Namespace: default
Priority: 0
Node: worker-node/192.168.1.11
Start Time: Thu, 22 Jul 2024 08:30:00 +0000
Labels: app=nginx
Annotations: <none>
Status: Running
IP: 10.244.1.5
IPs:
IP: 10.244.1.5
Containers:
nginx:
Container ID: docker://1234567890abcdef
Image: nginx:1.21
Image ID: docker-pullable://nginx@sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Thu, 22 Jul 2024 08:30:10 +0000
Ready: True
Restart Count: 0
Limits:
cpu: 500m
memory: 128Mi
Requests:
cpu: 250m
memory: 64Mi
Liveness: http-get http://:80/ delay=30s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:80/ delay=5s timeout=1s period=10s #success=1 #failure=3
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-f4k2j (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-f4k2j:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 1m default-scheduler Successfully assigned default/nginx-pod to worker-node
Normal Pulling 1m kubelet Pulling image "nginx:1.21"
Normal Pulled 1m kubelet Successfully pulled image "nginx:1.21" in 20s
Normal Created 1m kubelet Created container nginx
Normal Started 1m kubelet Started container nginx
Listing All Nodes
Nodes are the machines in your Kubernetes cluster that run your applications. Each Node contains the services necessary to run Pods, such as the container runtime and kubelet.
1. List Nodes
To list all Nodes in your cluster, use the kubectl get nodes
command:
kubectl get nodes
This command provides information about each Node, including its name, status, roles, version, and more.
NAME STATUS ROLES AGE VERSION
minikube Ready master 15d v1.20.2
2. Detailed Node Information
For a more detailed view of each Node, including their labels and resource capacity, use the -o wide
option:
kubectl get nodes -o wide
This will includes additional details such as the internal IP address and the operating system of each Node.
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready master 15d v1.20.2 192.168.49.2 <none> Ubuntu 20.04.1 LTS 5.4.0-66-generic docker://20.10.2
3. Node Descriptions
To get a complete description of a specific Node, including all its metadata, status, and allocated resources, use the following command:
kubectl describe node app-node
This will provides detailed information about the node named app-node in the Kubernetes cluster.
Name: app-node
Roles: <none>
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/hostname=app-node
node-role.kubernetes.io/app=app
Annotations: flannel.alpha.coreos.com/backend-data: {"VtepMAC":"aa:bb:cc:dd:ee:ff"}
flannel.alpha.coreos.com/backend-type: vxlan
flannel.alpha.coreos.com/public-ip: 192.168.1.10
CreationTimestamp: Wed, 21 Jul 2024 15:30:00 +0000
Taints: <none>
Unschedulable: false
Lease:
HolderIdentity: app-node
AcquireTime: <unset>
RenewTime: Thu, 22 Jul 2024 10:00:00 +0000
Conditions:
Type Status LastHeartbeatTime LastTransitionTime Reason Message
---- ------ ----------------- ------------------ ------ -------
MemoryPressure False Thu, 22 Jul 2024 10:00:00 +0000 Wed, 21 Jul 2024 15:30:00 +0000 KubeletHasSufficientMemory kubelet has sufficient memory available
DiskPressure False Thu, 22 Jul 2024 10:00:00 +0000 Wed, 21 Jul 2024 15:30:00 +0000 KubeletHasNoDiskPressure kubelet has no disk pressure
PIDPressure False Thu, 22 Jul 2024 10:00:00 +0000 Wed, 21 Jul 2024 15:30:00 +0000 KubeletHasSufficientPID kubelet has sufficient PID available
Ready True Thu, 22 Jul 2024 10:00:00 +0000 Wed, 21 Jul 2024 15:30:00 +0000 KubeletReady kubelet is posting ready status
Addresses:
InternalIP: 192.168.1.10
Hostname: app-node
Capacity:
cpu: 4
ephemeral-storage: 50Gi
hugepages-1Gi: 0
hugepages-2Mi: 0
memory: 16Gi
pods: 110
Allocatable:
cpu: 4
ephemeral-storage: 45Gi
hugepages-1Gi: 0
hugepages-2Mi: 0
memory: 15Gi
pods: 110
System Info:
Machine ID: 123456789abcdef
System UUID: 12345678-1234-1234-1234-123456789abc
Boot ID: 1234abcd-1234-abcd-1234-abcd1234abcd
Kernel Version: 5.10.0-1049-azure
OS Image: Ubuntu 20.04.2 LTS
Operating System: linux
Architecture: amd64
Container Runtime Version: docker://20.10.7
Kubelet Version: v1.21.1
Kube-Proxy Version: v1.21.1
PodCIDR: 10.244.0.0/24
PodCIDRs: 10.244.0.0/24
Non-terminated Pods: (7 in total)
Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE
--------- ---- ------------ ---------- --------------- ------------- ---
kube-system coredns-558bd4d5db-6g6gr 100m (2%) 200m (5%) 70Mi (0%) 170Mi (1%) 18d
kube-system coredns-558bd4d5db-pxgrt 100m (2%) 200m (5%) 70Mi (0%) 170Mi (1%) 18d
kube-system etcd-app-node 100m (2%) 0 (0%) 100Mi (0%) 0 (0%) 18d
kube-system kube-apiserver-app-node 250m (6%) 0 (0%) 512Mi (3%) 0 (0%) 18d
kube-system
Conclusion
Listing all Pods and Nodes in a Kubernetes cluster is a fundamental skill for managing and monitoring your applications. By using kubectl, you can efficiently get an overview of your resources, filter them based on labels, and retrieve detailed information for specific resources. These commands are invaluable for debugging, monitoring, and ensuring the health of your Kubernetes environment.
LHB Community is made of readers like you who share their expertise by writing helpful tutorials. Contact us if you would like to contribute.