How can I list all Kubernetes services along with the number of active pods associated with each service?
Currently, I can list all services with:
kubectl get services
I would like to add one additional column to the output, which lists active pod count for each service.
A service is basically a load balancer over a deployment (and a deployment is a replica set of multiple pods). So, chances are you want to be listing the deployments instead of the services in this case. Services and deployments are loosely coupled via tags, so there probably isn't a great way to go from services to pods directly.
I recommend kubectl get deploy -A
to view all deployments and their pod counts in all namespaces in this case.
Example output from the kube-system
namespace in our cluster (since it's not sensitive in any way)...
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system cluster-autoscaler-aws-cluster-autoscaler 1/1 1 1 231d
kube-system coredns 2/2 2 2 231d
kube-system ebs-csi-controller 2/2 2 2 231d
kube-system efs-csi-controller 2/2 2 2 231d
kube-system metrics-server 1/1 1 1 231d