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.
Error behavior
In minikube, only a simple execution is required to activate metrics-server:
1 | minikube addons enable metrics-server |
The system will feedback:
1 | * The 'metrics-server' addon is enabled |
Execute the list command again:
1 | minikube addons list |
It can also be seen that metrics-server has been activated:
1 | |-----------------------------|----------|--------------| |
But if we execute the top command:
1 | kubectl top pod |
What you get is the following error message:
1 | 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:
1 | kubectl get pod -n kube-system |
The following results can be obtained:
1 | 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:
1 | describe pod metrics-server-6754dbc9df-lhp9p -n kube-system |
The system display:
1 | 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。
Manually pull the image
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
1 | minikube ssh |
- Pull images from Alibaba’s repository
1 | docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server-amd64:v0.2.1 |
- Tag the image
1 | 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。
Modify the deployment file for metrics-server
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.
Execute:
1 | kubectl -n kube-system edit deployment metrics-server |
After execution, the metrics-server file will open in your system’s default editor,Such as:
1 | # 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:
1 | kubectl top pod |
In my environment, display:
1 | 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.