Reputation: 183
In an environment with 100 pods each with it's own label 'env=<>'. When I use the command "kubectl get pods --selector env=dev' it gives me 36 pods by listing them. However, I am interested in only the count i.e., 36 and do not want the pods to be listed. How do I accomplish this?
Upvotes: 2
Views: 3381
Reputation: 44687
You can get rid of the header if you use
kubectl get pods --selector env=dev --no-headers | wc -l
Upvotes: 6
Reputation: 729
You can use wc -l
to count the line of your output.
kubectl get pods --selector env=dev | wc -l
Keep in mind that the first line is the header so the number of pods will be that output -1
Upvotes: 1