In earlier versions of minikube (kubernetes), heapster was used to monitor clusters, and since version 1.8, it has gradually been upgraded to use metrics-server for resource monitoring. Installing metrics-server is simple, but it often leads to ImagePullBackOff errors due to network issues.
In minikube, only a simple execution is required to activate metrics-server:
minikube addons enable metrics-server
The system will feedback:
* The 'metrics-server' addon is enabled
Execute the list command again:
minikube addons list
It can also be seen that metrics-server has been activated:
But if we execute the top command：
kubectl top pod
What you get is the following error message:
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)
Note that metrics-server is not actually installed. WHY？
By executing the get pod command we look for the reason:
kubectl get pod -n kube-system
The following results can be obtained:
NAME READY STATUS RESTARTS AGE
As you can see, the metrics-server corresponding POD did not start successfully and is now in the ImagePullBackOff state。
Execute the describe command further to view the events:
describe pod metrics-server-6754dbc9df-lhp9p -n kube-system
The system display:
Type Reason Age From Message
This is clearer because the k8s.gcr.io cannot be accessed, resulting in the image not being pulled: metrics-server-amd64:v0.2.1 ，This results in the required POD not starting correctly。
To solve this problem, we first need to pull to the mirror. Since we can’t access k8s.gcr.io, we download it from the country and execute the following command at once:
- Log in to the minikube virtual machine
- Pull images from Alibaba’s repository
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.2.1
- Tag the image
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.2.1 k8s.gcr.io/metrics-server-amd64:v0.2.1
This results in a proper mirror image of metrics-server in minikube。
After you have an image locally, you will find that minikube still needs to take the image from k8s.gcr.io, and you need to modify the deployment file of metrics-server.
kubectl -n kube-system edit deployment metrics-server
After execution, the metrics-server file will open in your system’s default editor，Such as:
# Please edit the object below. Lines beginning with a '#' will be ignored,
On line 47 of the file, you can see that the current pull mode is: Always, which means that it will fetch from k8s.gcr.io regardless of whether there is already an image locally. Change the policy to: IfNotPresent, let the system take precedence over local mirrors.
After saving the file, the system will automatically update the POD, there is no need to re-enable this addon.
After you complete the next steps, you are ready to execute the top command:
kubectl top pod
In my environment, display:
NAME CPU(cores) MEMORY(bytes)
Of course, the metrics-server deployment is activated to execute this simple top command, but to get more monitoring information through the metrics API, and to configure scaling applications that are automated based on conditions.