I am able to get the jobs under the namespace using kubectl command:
kubectl get jobs --namespace xxx
This is giving me the jobs information
I would like to print the count of jobs using kubectl command. How to do that?
CodePudding user response:
If you are want to get number of job that are running in namespace you can get it using like this also
kubectl get jobs -n dcs | grep -v NAME | wc -l
CodePudding user response:
You can use the, wc or jq for this
kubectl get jobs --output name | wc -l
with jq :
kubectl get jobs --output json | jq -j '.items | length'
CodePudding user response:
go-template
way, no pipes or installation needed. Just good old kubectl:
kubectl get jobs --namespace xxx -o go-template='{{printf "%d\n" (len .items)}}'
len
is an inbuild function in go-template
to return the number of elements to its argument. Eg: items
.