Menu Close

K8 – How to get list of pods in kubernetes

Here, we will see how to get list of pods in kubernetes. There are many ways to do that. We will see one by one with example.

We will be using kubectl command line tool to get list of pods in kubernetes.

Get list of pods

$ kubectl get pods --all-namespaces

 NAMESPACE     NAME                         READY   STATUS    RESTARTS   AGE

 default       mongo-db-6ccb7d655-j7s4x     1/1     Running   1          99m

 default       ngnix-server                 1/1     Running   0          79m

 kube-system   coredns-74ff55c5b-g9mm6      1/1     Running   5          108d

Get list of pods of default namespace

$ kubectl get pods 

 NAME                       READY   STATUS    RESTARTS   AGE

 mongo-db-6ccb7d655-j7s4x   1/1     Running   1          64m

 ngnix-server               1/1     Running   0          43m

or

$ kubectl get pods -n default

 NAME                       READY   STATUS    RESTARTS   AGE

 mongo-db-6ccb7d655-j7s4x   1/1     Running   1          101m

 ngnix-server               1/1     Running   0          81m

Get pod with pod name

Syntanx:

 $ kubectl get pod pod_name  

Example:

$ kubectl get pod ngnix-server

 NAME           READY   STATUS    RESTARTS   AGE

 ngnix-server   1/1     Running   0          44m

Get list of pods with labels

Syntax:

  $ kubectl get pod -l=label_name

Example:

$ kubectl get pod -l=app=mongo-db

NAME                       READY   STATUS    RESTARTS   AGE

mongo-db-6ccb7d655-j7s4x   1/1     Running   1          51m


$ kubectl get pods --show-labels

NAME                       READY   STATUS    RESTARTS   AGE   LABELS

mongo-db-6ccb7d655-j7s4x   1/1     Running   1          30m   app=mongo-db,pod-template-hash=6ccb7d655

ngnix-server               1/1     Running   0          10m   run=ngnix-server

To learn more about golang, Please refer given below link:

https://techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/

Posted in kubernetes

Leave a Reply

Your email address will not be published. Required fields are marked *