最近才知道 kubectl top 並不是天生就可以用的,需要另外安裝 metrics-server

Install

直接 apply 最新版的 metrics-server

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

看看服務有沒有跑起來

1
2
kubectl logs -n kube-system -l k8s-app=metrics-server
kubectl top po -A

疑難排解

Error: x509: cannot validate certificate

  1. edit deployment/metrics-server
1
kubectl edit deployment -n kube-system metrics-server
  1. add - --kubelet-insecure-tls to args:
1
2
3
4
5
6
7
8
9
10
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=4443
- --kubelet-insecure-tls
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --kubelet-use-node-status-port
image: k8s.gcr.io/metrics-server/metrics-server:v0.4.1
imagePullPolicy: IfNotPresent

refs.