Mark Ku's Blog

Introduction

In Kubernetes, Metrics Server is an important component that provides real-time metric data on cluster resource usage. These metrics are crucial for managing and scaling the resource usage of Pods and nodes. This article will introduce how to install, configure, and view data from the Metrics Server.

Kubernetes Has Two Main Types of Metrics

  • Core metrics: Data is collected from Kubelet and cAdvisor, then provided by the metrics-server to the Horizontal Pod Autoscaler (HPA) and other services for use.
  • Custom Metrics: Data metrics collected by Prometheus.

1. Install Metrics Server

First, we need to install Metrics Server. Its installation and configuration are very simple and can be deployed directly via a Kubernetes YAML file. Run the following command to download and apply the latest version of the Metrics Server deployment configuration:

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

This will automatically download the latest metrics-server configuration from GitHub and deploy it to your Kubernetes cluster.

2. Configure the Default Editor to vim

In Kubernetes, certain commands (like kubectl edit) use the default editor for editing. If you're used to using vim, you can set the KUBE_EDITOR environment variable to change the default editor. Run the following command to set it:

export KUBE_EDITOR=vim

This way, every time you execute the kubectl edit command, the system will automatically launch vim for editing.

3. Check the Metrics Server's Running Status

After installing and deploying Metrics Server, you can check its running status with the following commands:

View the Metrics Server Logs:

kubectl logs -n kube-system -l k8s-app=metrics-server

This will display the logs for metrics-server, allowing you to check if it has started successfully and is running correctly.

View Cluster Resource Usage:

kubectl top po -A

This command displays the resource usage of Pods in all namespaces, including CPU and memory consumption. This helps you understand the overall resource consumption of the cluster.

4. Modify the Metrics Server Configuration

Sometimes, you may need to modify the configuration of metrics-server, for example, to adjust resource limits or change other parameters. You can use the following command to edit the Metrics Server's Deployment:

kubectl edit deployment -n kube-system metrics-server

This will open an editor where you can modify the YAML configuration as needed.

In the args section, add a line

- --kubelet-insecure-tls

to add the setting for certificate checking.

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

After updating, restart metrics and confirm the deployment status

Use the following command to ensure the changes have been applied and there are no errors.

kubectl rollout status deployment metrics-server -n kube-system

This will display the rolling update status of metrics-server. When all Pods have been successfully updated, it will show "deployment "metrics-server" successfully rolled out".

Check the metrics-server status

kubectl get pods -n kube-system -l k8s-app=metrics-server

Test

kubectl top get nodes
kubectl top get pods
kubectl top command
kubectl top command

Conclusion

Metrics Server is a very useful component in Kubernetes that can help you better manage resource usage within your cluster. Through this article, you have learned how to install, configure, and use the Metrics Server, as well as how to view and modify its deployment configuration. Hopefully, these steps will help you manage resources in your Kubernetes cluster more efficiently.

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11