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?
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"
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/
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}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With