kubectl - format the resource quota values in json format

南笙酒味 提交于 2020-01-16 19:10:28

问题


One way to get the resource quota values in kubernetes is to use the following command

>kubectl describe resourcequotas
Name:                   default-quota
Namespace:              my-namespace
Resource                Used     Hard
--------                ----     ----
configmaps              19       100
limits.cpu              13810m   18
limits.memory           25890Mi  36Gi

But issue is this display all the values in text file format. Anyone knows how I can get in json format!

Of course, I can parse the output and get the individual entry and construct the json.

kubectl describe quota  | grep limits.cpu | awk '{print $2}'
13810m

But I am looking for something inbuilt or some quick way of doing it. Thanks for your help.


回答1:


Thanks for your messages. Let me answer my own question, I have found one.

jq has solved my problem.

To get the Max limit of resources in json format

kubectl get quota -ojson | jq -r .items[].status.hard

To get the Current usage of resources in json format

kubectl get quota -ojson | jq -r .items[].status.used


来源:https://stackoverflow.com/questions/56250571/kubectl-format-the-resource-quota-values-in-json-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!