{"id":247075,"date":"2022-07-16T09:56:49","date_gmt":"2022-07-16T01:56:49","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=247075"},"modified":"2022-07-04T12:57:21","modified_gmt":"2022-07-04T04:57:21","slug":"kube-capacity-cli","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/kube-capacity-cli.html","title":{"rendered":"Kube-capacity CLI \u67e5\u770b Kubernetes\u6280\u5de7"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nKube-capacity \u662f\u4e00\u4e2a\u7b80\u5355\u800c\u5f3a\u5927\u7684 CLI\uff0c\u5b83\u63d0\u4f9b\u4e86Kubernetes\u96c6\u7fa4\u4e2d\u8d44\u6e90\u8bf7\u6c42\u3001\u9650\u5236\u548c\u5229\u7528\u7387\u7684\u6982\u89c8\u3002\u5b83\u5c06\u8f93\u51fa\u7684\u6700\u4f73\u90e8\u5206\u7ed3\u5408kubectl top\u5230kubectl describe\u4e00\u4e2a\u6613\u4e8e\u4f7f\u7528\u7684\u96c6\u4e2d\u4e8e\u96c6\u7fa4\u8d44\u6e90\u7684 CLI \u4e2d\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u4e0d\u8fc7\u50cf\u8fd9\u6837\u7684\u5de5\u5177\u786e\u5b9e\u597d\u7528\u4e00\u4e9b\uff0c\u6bd4\u5982\u6211\u60f3\u770b\u8fd9\u4e2akube-system\u4e0b\u6709\u54ea\u4e9bpod\u6709\u6ca1\u6709\u8bbe\u7f6erequest\u548climit\u7684\u65f6\u5019\uff0c\u5b9e\u9645\u4e0a\uff0c\u6211\u9700\u8981\u8f93\u5165\u4e00\u6bb5\u5f88\u957f\u7684\u547d\u4ee4\u624d\u80fd\u5217\u51fa\uff0c\u800c\u4e14\u9700\u8981\u4e00\u4e9b\u8c03\u8bd5,\u8fd9\u770b\u8d77\u6765\u4e0d\u662f\u7279\u522b\u65b9\u4fbf\u3002<\/p>\n

# kubectl get pod -n kube-system -o=custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,PHASE:.status.phase,Request-cpu:.spec.containers\\[0\\].resources.requests.cpu,Request-memory:.spec.containers\\[0\\].resources.requests.memory,Limit-cpu:.spec.containers\\[0\\].resources.limits.cpu,Limit-memory:.spec.containers\\[0\\].resources.limits.memory\r\nNAME NAMESPACE PHASE Request-cpu Request-memory Limit-cpu Limit-memory\r\ncalico-kube-controllers-7d4c6544cc-g6x6q kube-system Running <none> <none> <none> <none>\r\ncalico-node-4fjn8 kube-system Running 250m <none> <none> <none>\r\ncalico-node-7nbpj kube-system Running 250m <none> <none> <none>\r\ncalico-node-qvdlr kube-system Running 250m <none> <none> <none>\r\ncoredns-7977f69688-4nz9q kube-system Running 100m 70Mi <none> 170Mi\r\ncoredns-7977f69688-frkt5 kube-system Running 100m 70Mi <none> 170Mi\r\netcd-k8s-master1 kube-system Running 100m 100Mi <none> <none>\r\netcd-k8s-master2 kube-system Running 100m 100Mi <none> <none>\r\netcd-k8s-master3 kube-system Running 100m 100Mi <none> <none>\r\nkube-apiserver-k8s-master1 kube-system Running 250m <none> <none> <none><\/pre>\n

\u90a3\u4e48\u8fd9\u4e2a\u5de5\u5177\u5b9e\u9645\u4e0a\u89e3\u51b3\u7684\u95ee\u9898\u5c31\u662f\u5e2e\u52a9\u6211\u4eec\u5feb\u901f\u67e5\u770b\u6982\u89c8\u6574\u4e2a\u96c6\u7fa4\u548cpod\u7684\u8d44\u6e90\u914d\u7f6e\u60c5\u51b5\u3002<\/p>\n

\u5b89\u88c5<\/strong><\/div>\n

Go \u4e8c\u8fdb\u5236\u6587\u4ef6\u7531GoReleaser\u968f\u6bcf\u4e2a\u7248\u672c\u81ea\u52a8\u6784\u5efa\u3002\u8fd9\u4e9b\u53ef\u4ee5\u5728\u6b64\u9879\u76ee\u7684 GitHub\u53d1\u5e03\u9875\u9762\u4e0a\u8bbf\u95ee\u3002<\/p>\n

    \n
  • https:\/\/github.com\/goreleaser\/goreleaser<\/em><\/li>\n
  • \u00a0https:\/\/g<\/em>ithub.com\/robscott\/kube-capacity\/releases<\/li>\n<\/ul>\n
    Homebrew<\/strong><\/div>\n

    \u8fd9\u4e2a\u9879\u76ee\u53ef\u4ee5\u7528Homebrew\u5b89\u88c5\uff1a<\/p>\n

    brew tap robscott\/tap\r\nbrew install robscott\/tap\/kube-capacity<\/pre>\n
    Krew<\/strong><\/div>\n

    \u8fd9\u4e2a\u9879\u76ee\u53ef\u4ee5\u7528Krew\u5b89\u88c5\uff1a<\/p>\n

    kubectl krew install resource-capacity<\/pre>\n
    \u7528\u6cd5<\/strong><\/div>\n

    \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ckube-capacity \u5c06\u8f93\u51fa\u4e00\u4e2a\u8282\u70b9\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b CPU \u548c\u5185\u5b58\u8d44\u6e90\u8bf7\u6c42\u7684\u603b\u6570\u4ee5\u53ca\u5728\u5b83\u4eec\u4e0a\u8fd0\u884c\u7684\u6240\u6709 pod \u7684\u9650\u5236\u3002\u5bf9\u4e8e\u5177\u6709\u591a\u4e2a\u8282\u70b9\u7684\u96c6\u7fa4\uff0c\u7b2c\u4e00\u884c\u8fd8\u5c06\u5305\u62ec\u96c6\u7fa4\u8303\u56f4\u7684\u603b\u6570\u3002\u8be5\u8f93\u51fa\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

    \"\"<\/p>\n

    \u5305\u62ec Pod<\/strong><\/div>\n

    \u5bf9\u4e8e\u66f4\u8be6\u7ec6\u7684\u8f93\u51fa\uff0ckube-capacity \u53ef\u4ee5\u5728\u8f93\u51fa\u4e2d\u5305\u542b pod\u3002\u5f53-p\u6216--pods\u88ab\u4f20\u9012\u7ed9 kube-capacity \u65f6\uff0c\u5b83\u5c06\u5305\u542b\u5982\u4e0b\u6240\u793a\u7684\u7279\u5b9a\u4e8e pod \u7684\u8f93\u51fa<\/p>\n

    \"\"<\/p>\n

    \u5305\u62ec\u5229\u7528\u7387<\/strong><\/div>\n

    \u4e3a\u4e86\u5e2e\u52a9\u4e86\u89e3\u8d44\u6e90\u5229\u7528\u7387\u4e0e\u914d\u7f6e\u7684\u8bf7\u6c42\u548c\u9650\u5236\u7684\u6bd4\u8f83\uff0ckube-capacity \u53ef\u4ee5\u5728\u8f93\u51fa\u4e2d\u5305\u542b\u5229\u7528\u7387\u6307\u6807\u3002\u8bf7\u52a1\u5fc5\u6ce8\u610f\uff0c\u6b64\u8f93\u51fa\u4f9d\u8d56\u4e8e\u96c6\u7fa4\u4e2d\u7684metrics-server\u6b63\u5e38\u8fd0\u884c\u3002\u5f53-u\u6216--util\u88ab\u4f20\u9012\u7ed9 kube-capacity \u65f6\uff0c\u5b83\u5c06\u5305\u542b\u5982\u4e0b\u6240\u793a\u7684\u8d44\u6e90\u5229\u7528\u7387\u4fe1\u606f\uff1a<\/p>\n

    \"\"<\/p>\n

    \u5305\u62ec Pod \u548c\u5229\u7528\u7387<\/strong><\/div>\n

    \u5bf9\u4e8e\u66f4\u8be6\u7ec6\u7684\u8f93\u51fa\uff0ckube-capacity \u53ef\u4ee5\u5728\u8f93\u51fa\u4e2d\u5305\u542b pod \u548c\u8d44\u6e90\u5229\u7528\u7387\u3002\u5f53--util\u548c--pods\u4f20\u9012\u7ed9 kube-capacity \u65f6\uff0c\u5b83\u5c06\u4ea7\u751f\u5982\u4e0b\u6240\u793a\u7684\u5bbd\u8f93\u51fa\uff1a<\/p>\n

    \"\"<\/p>\n

    \u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6765\u81ea pod \u7684\u5229\u7528\u7387\u6570\u5b57\u53ef\u80fd\u4e0d\u4f1a\u4e0e\u603b\u8282\u70b9\u5229\u7528\u7387\u76f8\u52a0\u3002\u4e0e\u8282\u70b9\u548c\u96c6\u7fa4\u7ea7\u522b\u6570\u5b57\u4ee3\u8868 pod \u503c\u603b\u548c\u7684\u8bf7\u6c42\u548c\u9650\u5236\u6570\u5b57\u4e0d\u540c\uff0c\u8282\u70b9\u6307\u6807\u76f4\u63a5\u6765\u81ea\u6307\u6807\u670d\u52a1\u5668\uff0c\u5e76\u4e14\u53ef\u80fd\u5305\u62ec\u5176\u4ed6\u5f62\u5f0f\u7684\u8d44\u6e90\u5229\u7528\u7387\u3002<\/p>\n

    \u6392\u5e8f<\/strong><\/div>\n

    \u8981\u7a81\u51fa\u663e\u793a\u5177\u6709\u6700\u9ad8\u6307\u6807\u7684\u8282\u70b9\u3001pod \u548c\u5bb9\u5668\uff0c\u60a8\u53ef\u4ee5\u6309\u5404\u79cd\u5217\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n

    \"\"<\/p>\n

    \u663e\u793a Pod \u8ba1\u6570<\/strong><\/div>\n

    \u8981\u663e\u793a\u6bcf\u4e2a\u8282\u70b9\u548c\u6574\u4e2a\u96c6\u7fa4\u7684 pod \u6570\u91cf\uff0c\u53ef\u4ee5\u901a\u8fc7--pod-count\u53c2\u6570\uff1a<\/p>\n

    \"\"<\/p>\n

    \u6309\u6807\u7b7e\u8fc7\u6ee4<\/strong><\/div>\n

    \u5bf9\u4e8e\u66f4\u9ad8\u7ea7\u7684\u4f7f\u7528\uff0ckube-capacity \u8fd8\u652f\u6301\u6309 pod\u3001\u547d\u540d\u7a7a\u95f4\u548c\/\u6216\u8282\u70b9\u6807\u7b7e\u8fdb\u884c\u8fc7\u6ee4\u3002\u4ee5\u4e0b\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u8fc7\u6ee4\u5668\uff1a<\/p>\n

    kube-capacity --pod-labels app=nginx kube-capacity --namespace \u9ed8\u8ba4 kube-capacity --namespace-labels team=api kube-capacity --node-labels kubernetes.io\/role=node<\/pre>\n
    JSON \u548c YAML \u8f93\u51fa<\/strong><\/div>\n

    \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ckube-capacity \u5c06\u4ee5\u8868\u683c\u683c\u5f0f\u63d0\u4f9b\u8f93\u51fa\u3002\u8981\u4ee5 JSON \u6216 YAML \u683c\u5f0f\u67e5\u770b\u6b64\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528\u8f93\u51fa\u6807\u5fd7\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\u547d\u4ee4\uff1a<\/p>\n

    kube-capacity --pods --output json kube-capacity --pods --containers --util --output yaml<\/pre>\n

    \u652f\u6301\u7684\u6807\u5fd7<\/p>\n

    \"\"<\/p>\n

    \u5148\u51b3\u6761\u4ef6<\/strong><\/div>\n

    \u4efb\u4f55\u8bf7\u6c42\u96c6\u7fa4\u5229\u7528\u7387\u7684\u547d\u4ee4\u90fd\u4f9d\u8d56\u4e8e\u96c6\u7fa4\u4e0a\u8fd0\u884c\u7684metrics-server\u3002\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b98\u65b9helm chart\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u4e0d\u8fc7\u50cf\u8fd9\u6837\u7684\u5de5\u5177\u786e\u5b9e\u597d\u7528\u4e00\u4e9b\uff0c\u6bd4\u5982\u6211\u60f3\u770b\u8fd9\u4e2akube-system\u4e0b\u6709\u54ea\u4e9bpod\u6709\u6ca1\u6709\u8bbe\u7f6erequest\u548cli […]<\/p>\n","protected":false},"author":323,"featured_media":107067,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-247075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/247075","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=247075"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/247075\/revisions"}],"predecessor-version":[{"id":247090,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/247075\/revisions\/247090"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/107067"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=247075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=247075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=247075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}