This note will record how to deploy Metrics Server components.
Kubernetes Cluster v1.16
Environmental requirements
Metrics Server has special requirements for networks and clusters. This requirement is not the default configuration in some clusters, so you must first confirm whether the requirements are met.
# Since using Kubernetes, there are endless documents and resources. In many tutorials, apply directly. Anyway, it can be used, indicating that these dependencies are enabled in most clusters. But even if we know that this can complete the deployment task, we still have to read the documentation. If you don't read these documents, you don't know how these things work, and it's difficult to troubleshoot problems.
Metrics Server must be reachable from kube-apiserver
The kube-apiserver must be correctly configured to enable an aggregation layer
Configure the Aggregation Layer-Kubernetes
checks the /etc/kubernetes/manifests/kube-apiserver.yaml option, which is already enabled by default.
Nodes must have kubelet authorization configured to match Metrics Server configuration
Container runtime must implement a container metrics RPCs
Install the build
The second step, modify the configuration information
Download the components.yaml file and modify it:
1) We need to modify the mirror address in the YAML file to use a private mirror warehouse;
2) Add --kubelet-preferred-address-types=InternalIP and --kubelet-insecure- tls option;
The third step, application configuration file
kubectl apply -f "/path/to/components.yaml"
Summary of common errors
Metrics not available for pod
# kubectl top -n kube-system pod W0702 10:48:07.400630 6619 top_pod.go:266] Metrics not available for pod kube-system/coredns-58cc8c89f4-6czm4, age: 4267h8m49.400600321s error: Metrics not available for pod kube-system/coredns-58cc8c89f4-6czm4, age: 4267h8m49.400600321s
Solve by adding --kubelet-preferred-address-types=InternalIP and --kubelet-insecure-tls options;
unable to fetch pod metrics for pod
E0702 02:39:09.777832 1 reststorage.go:160] unable to fetch pod metrics for pod default/counter: no metrics known for pod E0702 02:39:09.777843 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/etcd-k8s-master-02: no metrics known for pod E0702 02:39:09.777863 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/fluentd-p6d29: no metrics known for pod E0702 02:39:09.777874 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/kube-proxy-xdh2z: no metrics known for pod E0702 02:39:09.777885 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/etcd-k8s-master-01: no metrics known for pod E0702 02:39:09.777900 1 reststorage.go:160] unable to fetch pod metrics for pod kube-system/kube-proxy-jrpnd: no metrics known for pod
Solve by adding --kubelet-preferred-address-types=InternalIP and --kubelet-insecure-tls options;
references
Kubernetes metrics-server Installation
Installing the Kubernetes Metrics Server
Kubernetes Metrics unable to fetch pod/node metrics - Stack Overflow