How to list all running pod names in Kubernetes

list all running pod names in Kubernetes

To list all running pod name, We can use the below 2 easy ways

  • Using the Linux awk command
  • Using JSON path

Using the Linux awk command

We can use the Linux awk command to filter the pod output and just print the pod name below

 ➜  kubectl get pods -o wide -n default |  awk -F' ' '{print $1}' 

Output:

NAME
nginx

Using Jsonpath

By using JSONPath expressions, We can filter specific fields in the JSON object and can format the output. In our case, We just have to display the pod name “{.items..metadata.name}”

➜  kubectl get pods --output=jsonpath={.items..metadata.name}

Output:


nginx

Addition Commands to list pod names with more detailed information

List all pods in the current namespace

➜  kubectl get pods -o wide   
NAME    READY   STATUS    RESTARTS   AGE   IP          NODE           NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          14s   10.42.0.9   controlplane              

List all pods in a specific namespace

➜  kubectl get pods -o wide -n default
NAME    READY   STATUS    RESTARTS   AGE   IP          NODE           NOMINATED NODE   READINESS GATES
nginx   1/1     Running   0          93s   10.42.0.9   controlplane              

List all pods from all the namespace

➜  kubectl get pods -o wide --all-namespaces 
NAMESPACE     NAME                                      READY   STATUS      RESTARTS   AGE     IP          NODE           NOMINATED NODE   READINESS GATES
kube-system   local-path-provisioner-7b7dc8d6f5-h5kfm   1/1     Running     0          8m15s   10.42.0.6   controlplane              
kube-system   coredns-b96499967-hrkbg                   1/1     Running     0          8m15s   10.42.0.5   controlplane              
kube-system   helm-install-traefik-crd-w6k8h            0/1     Completed   0          8m15s   10.42.0.3   controlplane              
kube-system   metrics-server-668d979685-6fvhn           1/1     Running     0          8m15s   10.42.0.4   controlplane              
kube-system   helm-install-traefik-62lr7                0/1     Completed   2          8m15s   10.42.0.2   controlplane              
kube-system   svclb-traefik-fstj8                       2/2     Running     0          7m29s   10.42.0.8   controlplane              
kube-system   traefik-7cd4fcff68-67j2r                  1/1     Running     0          7m30s   10.42.0.7   controlplane              
default       nginx                                     1/1     Running     0          35s     10.42.0.9   controlplane              

List all the pod names using the JSON path

➜  kubectl get pods --output=jsonpath={.items..metadata.name} --all-namespaces
local-path-provisioner-7b7dc8d6f5-h5kfm coredns-b96499967-hrkbg helm-install-traefik-crd-w6k8h metrics-server-668d979685-6fvhn helm-install-traefik-62lr7 svclb-traefik-fstj8 traefik-7cd4fcff68-67j2r nginx
controlplane ~ ➜  

Click,here to know more about Kubernetes services

Good Luck with your leanring

Similar Posts