
Metrics server is a scalable cluster add-on for the Kubernetes built-in autoscaling pipelines. It is a critical element to scale pods in the Kubernetes cluster. It is designed to automatically scale up or down your application workloads using the Kubernetes Horizontal Pod Autoscaler.
Metrics server works by retrieving kubelet metrics from each worker node, collecting CPU and memory usage for each application workload then use the Kubernetes API server to expose CPU and memory usage metrics. Then, Horizontal Pod Autoscaler fetches CPU and memory usage metrics and scales up or down your application deployment pods based on metrics observation and target threshold.
The main features of using Kubernetes metrics server are:
This guide shows you how to install Metrics server on Vultr Kubernetes Engine.
kubectl CLI installed and configured in your local machine.First, add the Helm repository for the Metrics server.
Next, update the Helm repository to the latest version.
Then, verify the added repository.
Sample output.
After that, create a namespace for the Metrics server.
Next, set default namespace to metrics-server.
Before installing the Metrics server, obtain the default configuration value from the Helm repo and save it to the file metrics-server.values.
Next, edit the file metrics-server.values.
Change the desired configuration to file.
Now, deploy the Metrics server to Kubernetes.
Sample output.
After the successful deployment, verify it using the following command.
Sample output.
To verify other components, run.
Sample output.
The simple and easiest way to verify the metrics data using the kubectl top command. You can verify the resource usage at the cluster level and at the Pods level.
To verify the resource usage at the cluster level, run:
This command will show you the resource usage for both CPU and memory on each worker node.
To verify the resource usage at the Pod level, run:
This command will show you the CPU usage in millicores and memory usage in Mebibytes.
In this section, you will configure Horizontal Pod Autoscaling to grow and shrinks Pods automatically based on resource utilization.
First, create a deployment to test Horizontal Pod Autoscaling.
Add the following configurations.
Apply the above manifest to the Kubernetes cluster.
Verify the deployment.
Sample output.
Next, create the Horizontal Pod Autoscaler CRD to configure Horizontal Pod Autoscaler (HPA) on your deployment
Add the following configurations.
The above configuration will create a Horizontal Pod Autoscaler on the sample-app deployment with CPU max value set to 50 and scaling between 2-6 replicas.
Apply the manifest to the Kubernetes cluster.
If you don't want to run Horizontal Pod Autoscaler using the above method then you can deploy it via the kubectl autoscale command.
Now, verify the HPA creation using the following command.
You should the the current usage%/target usage% in the TARGET column.
To see the detailed information of your HPA, run:
You should see the detail overview of your HPA deployment in the following output.
Your sample-app is now autoscaled as per resource usage. You can verify it using the following command.
Sample output.
You can also verify your Pods using the following command.
Sample output.
You can visit the metrics-server official release page to check the latest available versions.
To upgrade the Metrics server stack to the latest version, run the following command.
You can check the helm upgrade command documentation for more information.
You can remove your complete Metrics server installation from your system using the helm uninstall command.
The above command will remove all metrics-server related components from your server. You will also need to delete the metrics-server namespace from your system. To delete the namespace, run the following command.
You've finished deploying the Metrics server on the Vultr Kubernetes Engine. Metrics server is a powerful tool for monitoring Kubernetes autoscaling metrics based on CPU utilization or memory usage. For more information, check out the Metrics server official GitHub page.
0 Comments
Be the first to comment and share your perspective with the community.