From 55ac86b26373dfadf31b09515fe00a0f16b19b96 Mon Sep 17 00:00:00 2001 From: roc Date: Mon, 6 May 2024 14:40:38 +0800 Subject: [PATCH] update at 2024-05-06 14:40:38 --- content/appendix/kubectl/get-raw.md | 76 +++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 9 deletions(-) diff --git a/content/appendix/kubectl/get-raw.md b/content/appendix/kubectl/get-raw.md index a607103..120d45e 100644 --- a/content/appendix/kubectl/get-raw.md +++ b/content/appendix/kubectl/get-raw.md @@ -27,20 +27,78 @@ kubectl get --raw=/api/v1/namespaces/monitoring/pods/node-exporter-n5rz2:9100/pr kubectl get --raw=/api/v1/nodes/11.185.19.21/proxy/stats/summary ``` -## 测试 Resource Metrics API +## 查询 Resource Metrics -获取指定 namespace 下所有 pod 指标: + + + + ```bash + kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/test-ns/pods/" + ``` + + :::tip[注意] + + 注意替换 `test-ns` (ns 名称)。 + ::: + + ![](https://image-host-1251893006.cos.ap-chengdu.myqcloud.com/2023%2F09%2F25%2F20230925162846.png) + + + + + + ```bash + kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/test-ns/pods/test-sts-0" + ``` + + :::tip[注意] + + 注意替换 `test-ns`(ns 名称)和 `test-sts-0` (Pod 名称)。 + + ::: + + ![](https://image-host-1251893006.cos.ap-chengdu.myqcloud.com/2023%2F09%2F25%2F20230925162948.png) + + + + +## 查询 Custom Metrics + +1. 查看有哪些可用的 custom metrics 指标: ```bash -kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/ns-prjzbsxs-1391012-production/pods/" +kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/" ``` -![](https://image-host-1251893006.cos.ap-chengdu.myqcloud.com/2023%2F09%2F25%2F20230925162846.png) +2. 查询某个指标的值: -获取指定 pod 的指标: + + -```bash -kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces/ns-prjzbsxs-1391012-production/pods/mixer-engine-0" -``` + ```bash + kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/test-ns/pods/*/k8s_pod_gpu_used" + ``` + + :::tip[注意] + + 注意替换 `test-ns`(ns 名称) 和 `k8s_pod_gpu_used` (指标名称)。 + + ::: + + + + + + ```bash + kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/test-ns/pods/test-sts-0/k8s_pod_gpu_used" + ``` + + :::tip[注意] + + 注意替换 `test-ns`(ns 名称)、`test-sts-0`(Pod 名称)、`k8s_pod_gpu_used`(指标名称)。 + + ::: + + + -![](https://image-host-1251893006.cos.ap-chengdu.myqcloud.com/2023%2F09%2F25%2F20230925162948.png)