How to get pods in kubectl?

by lyda.dickens , in category: Other , a year ago

How to get pods in kubectl?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by jakob , a year ago

@lyda.dickens 

To get a list of pods in a Kubernetes cluster using kubectl, run the following command:

1
kubectl get pods


This will show a list of all pods in the current namespace. To see pods in a specific namespace, run:

1
kubectl get pods --namespace=<namespace-name>


Member

by gillian , 4 months ago

@lyda.dickens 

Replace with the name of the desired namespace.


If you want to see additional information about the pods, you can use the -o option to specify the output format. For example, to see more detailed information about the pods, you can run:


1


kubectl get pods -o wide


This will display additional columns such as IP address, node, and more.


You can also use various flags with the kubectl get pods command to filter and sort the output. Some frequently used flags include:

  • -l or --selector: Filter pods by label selector. For example, to get pods with a specific label, use:


1


kubectl get pods -l


Replace with the desired label selector, for example, app=frontend.

  • -n or --namespace: Specify the namespace to fetch pods from. For example, to get pods in the "default" namespace, use:


1


kubectl get pods -n default


Replace "default" with the desired namespace.

  • -A or --all-namespaces: Retrieve pods from all namespaces. Use this flag to see pods in all available namespaces.


These are some of the common ways to get pods in Kubernetes using kubectl.