Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print all pods along with cpu requirements kubernetes

Tags:

kubernetes

I want to print a list of all my pods with the CPU requirements in a column

I'm pretty sure its something like kubectl get pods 'spec.containers[].resources.limits.cpu'

Can someone please give me the correct syntax?

like image 666
R. Doolan Avatar asked Nov 07 '19 12:11

R. Doolan


Video Answer


3 Answers

You can also use the below command to get the cpu limit. It is more clearner than using jsonpath.

kubectl get po -o custom-columns="Name:metadata.name,CPU-limit:spec.containers[*].resources.limits.cpu"
like image 150
Tarul Kinra Avatar answered Dec 14 '22 08:12

Tarul Kinra


You can get the pods (in the default namespace) and their CPU Limit with the following command.

kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[].resources.limits.cpu}{"\n"}{end}'

We use the JSONPath output with the -o=jsonpath flag, and provide it with the data we want to extract.

You can find more details on using the JSONPath output at https://kubernetes.io/docs/reference/kubectl/jsonpath/

like image 37
chaosaffe Avatar answered Dec 14 '22 10:12

chaosaffe


Can you try below commands. replace cpu with memory to get memory requests and limits as well

CPU Requests
--------------
kubectl get po --all-namespaces \
 -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]}  {.name}:{.resources.requests.cpu}{'\n'}{end}{'\n'}{end}"

CPU Limits
-----------
kubectl get po --all-namespaces \
 -o=jsonpath="{range .items[*]}{.metadata.namespace}:{.metadata.name}{'\n'}{range .spec.containers[*]}  {.name}:{.resources.limits.cpu}{'\n'}{end}{'\n'}{end}"
like image 27
P Ekambaram Avatar answered Dec 14 '22 10:12

P Ekambaram