Wednesday, 7 January 2026

Useful kubectl commands

 


To get the list of all the nodes (physical nodes, e.g. EC2 instances in AWS EKS cluster) in the cluster:

kubectl get nodes

Output columns:
  • NAME e.g. ip-10-2-12-73.us-east-1.compute.internal
  • STATUS e.g. Ready
  • ROLES    <none>
  • AGE    e.g. 1d
  • VERSION e.g. v1.32.9-eks-ecaa3a6


kubectl get nodes -L node.kubernetes.io/instance-type,topology.kubernetes.io/zone,karpenter.sh/capacity-type

Output columns:
  • NAME e.g. ip-10-2-12-73.us-east-1.compute.internal
  • STATUS e.g. Ready
  • ROLES    <none>
  • AGE    e.g. 1d
  • VERSION e.g. v1.32.9-eks-ecaa3a6
  • INSTANCE-TYPE e.g. m7g.2xlarge
  • ZONE e.g. us-east-2a
  • CAPACITY-TYPE e.g. on-demand

kubectl get nodes -o wide

Output columns:
  • NAME e.g. ip-10-2-12-73.us-east-1.compute.internal
  • STATUS e.g. Ready
  • ROLES    <none>
  • AGE    e.g. 1d
  • VERSION e.g. v1.32.9-eks-ecaa3a6
  • INTERNAL-IP e.g. 10.2.12.73
  • EXTERNAL-IP e.g. <none> 
  • OS-IMAGE e.g. Amazon Linux 2023.9.20251208
  • KERNEL-VERSION e.g. 6.1.158-180.294.amzn2023.aarch64 or 6.1.132-147.221.amzn2023.x86_64
  • CONTAINER-RUNTIME e.g.  containerd://2.1.5

kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.providerID}{"\n"}{end}'

Output:

ip-10-2-12-73.us-east-2.compute.internal aws:///us-east-2a/i-039a9aaafa975358f
ip-10-2-13-147.us-east-2.compute.internal aws:///us-east-2a/i-0627bbbb3c15da009
...


List all pods (by default the output is grouped by NAMESPACE):

kubectl get pods -A -o wide 

Output columns:
  • NAMESPACE
  • NAME                                            
  • READY   (X/Y means X out of Y containers are ready)
  • STATUS
  • RESTARTS
  • AGE
  • IP
  • NODE
  • NOMINATED NODE
  • READINESS GATES

List all pods and sort them by NODE:

kubectl get pods -A -o wide --sort-by=.spec.nodeName 


To get a list of all namespaces in the cluster:

kubectl get ns

Output columns:
  • NAME e.g. default
  • STATUS e.g. Active
  • AGE e.g. 244d
...

No comments: