03 - Monitor Cluster Components

🏆 最常見的監控解法總覽

如:Metrics Server、Prometheus、Elastic Stack、Datadog、Dynatrace


Metrics Server

📈 metrics-server 是什麼?

metrics-server 是 K8s 中用來提供資源用量資訊(非歷史紀錄),例如:
  • $ kubectl top node          
  • $ kubectl top pod           
  • HPA(Horizontal Pod Autoscaler)的依據
  • Cluster Autoscaler 的依據(間接)

📌 注意:它不是用來做長期監控或歷史查詢(那是 Prometheus 的角色)。


🚀 安裝 metrics-server

建議方式(官方部署,預設會在 kube-system namespace 中建立 Deployment)

$ kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml             




Q: Deploy the Metrics Server in your Kubernetes cluster by applying the latest release components.yaml manifest using the following command:

$ kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml            


Q: It takes a few minutes for the metrics server to start gathering data.

$ kubectl top node                     


Q: Identify the node that consumes the most CPU(cores).

Ans: controlplane

$ kubectl top node                                                                   

$ kubectl top node --sort-by='cpu' --no-headers | head -1         

Here we have used `head -1` command to print the pod first in the order, which is the one that uses the most CPU(cores).


Q: Identify the POD that consumes the most Memory(bytes) in default namespace.

Ans: rabbit

$ kubectl top pod --sort-by='memory' --no-headers | head -1               


Q: Identify the POD that consumes the least CPU(cores) in default namespace.

Ans: lion

$ kubectl top pod --sort-by='cpu' --no-headers | tail -1                       

留言