V
V
Vadim2020-08-12 20:39:58
Kubernetes
Vadim, 2020-08-12 20:39:58

What kubernetes command to use to find the number of pods for each service?

Hey everyone,

the following command prints pods to the screen like this:
$ kubectl get pods -n mainspace

max-reporting-mrc-deployment-384743d45-spjnc 
max-reporting-mrc-deployment-6d9f966cf8-spjnc
npx-daemon-4njjs
npx-daemon-8h6nb


is it possible to use some command in cuber to display something similar to:
max-reporting-mrc-deployment               2
npx-daemon                                              2


where max-reporting-mrc-deployment is a sample pod or service, the numbers are the number of running pods?

all the best,
Vadim

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-08-13
@dodo512

kubectl get pods -n mainspace | sed 's/-[0-9].*//' | sort | uniq -c

kubectl get pods -n mainspace | awk -F'-[0-9]' '{a[$1]++}END{for (x in a) print x,a[x]}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question