Search code examples
kuberneteskubectlkubernetes-pod

Retrieve only the pod count without listing in kubernetes


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?


Solution

  • You can get rid of the header if you use

    kubectl get pods --selector env=dev --no-headers | wc -l