Updated April 13, 2023
Introduction to Kubernetes metrics server
With the help of metrics server in Kubernetes, we can easily keep track of the Resource usage which includes memory usage, CPU available in the Kubernetes by the use of metrics API. We can access these Metrics directly in two ways such as by the user or controller. User can access this by the use of command and for controller present inside the cluster that is for instance Horizontal Pod Auto-scaler which can be used to make decisions. So in short with the help of Metrics API in Kubernetes, we can easily determine the amount of resources that is begin consumed by the given pods or the node. But this value does not store by this API. In the coming section of the tutorial, we will discuss more its internal working and implementation in detail for better understanding and clarity for the beginners.
What is metrics-server?
As we have already seen that metrics server is used to keep track of the Resource usage on each node or given pod. Also, we can track this by using any command or by the user of the controller which will give us the metrics of Resource usage in our application. SO we can see a few of the points which can give us more idea about the metrics server in Kubernetes in detail see below;
1) It is a cluster-wide aggregator which contains the resource usage data.
2) By default it goes deployed in the cluster which we can create by the script called as Kube-up.script and represent as the Deployment object.
3) In case we are setting up the different Kubernetes setup, then in this case it can be deployed by the use of components.yml file which will contain the configuration.
4) By the use of Metrics server we can collect the resource usage data from the API, which is exposed by the K4 on each of the nodes presented, also it got registered with the main API by the use of Kubernetes aggregator.
As now we have a basic idea about the Metrics Server in Kubernetes, in the coming section, we can discuss more its use case and implementation in detail for better understanding and clarity.
Use cases Kubernetes metrics server
In this section we will discuss the scenarios where we can go and opt for Metrics Server, also we will see a few points which will tell when not to go for Metrics Server, so let’s get started;
1) When we want to achieve the Horizontal auto-scaling, which is based on the CPU/Memory then in this aces we should go for Metrics Server. Horizontal auto-scaling helps us to automatically scale the number of pods, replica set, and controllers.
2) Also it can be used when we want to perform the Vertical Autoscaling, which means we should automatically suggest or adjust the resource which is needed by the containers.
We also have a few scenarios where we should not consider Metrics Server let’s get started;
1) Suppose we want to have Horizontal Autoscaling but it is not based on the CPU/Memory, but on some other resource.
2) When we have Non-Kubernetes clusters in place.
3) When we want accurate resource usage metrics.
Kubernetes metrics server Installing
As we have seen that Kubernetes Metrics Server is a cluster aggregator which contains the resource usage data, which will be helpful for us to determine the usage of Resource on each of the nodes or pods we have in the cluster. This metrics server is basically used by the Kubernetes add-on, such as Kubernetes Dashboard and Horizontal Pod Amazon, also by default it is not deployed on the Amazon EKS clusters, we have to perform a few steps in order to achieve that.
In this section, we will discuss the installation part of the metrics server in Kubernetes, for this also requires to do some configuration. We have two ways by which we can install this which are mentioned below;
a) By using the YAML manifest
b) Or by making use of the official Helm Chart.
But we have a few commands by which we can easily install this metrics server, which can be done by the main use of components.yml manifest file, follow the below sets of commands to install it and verify it if that’s work fine see below;
a) To install using the components.yml manifest file un below command;
e.g.:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
b) Now we will require to validate or verify our installation, for this, we can make use of the below command;
e.g.:
kubectl get deployment metrics-server -n kube-system
In this way, we can install the Metrics server for our pods or nods in the cluster, but we will require to have the components.yaml file in place in order to execute the above command properly, so you can download the latest file from here for your reference see below;
URL:
https://github.com/kubernetes-sigs/metrics-server/releases
Kubernetes metrics server api examples
We can discover the API with the below path mentioned
e.g.:
1) /apis/metrics.k8s.io/
2) k8s.io/api/core/v1
Kubernetes metrics server Configuration
Let’s have n look at the configuration which needs to be done according to the type of cluster we have in place, We require to change a few flags which need to be changed in the Metrics Server, let’s get started
1) –kubelet-preferred-address-types: this will help in determining the address of the node to which we want to connect.
2) –kubelet-insecure-tls: this is for testing purposes only; it will not verify the CA of the certificate which is presented by the Kubelets.
3) –requestheader-client-ca-file: This configuration will help us to specify the root certificate, which will help in verifying the client certificate which is coming in the incoming requests.
Use the below command to get the fill metrics server list,
docker run –rm k8s.gcr.io/metrics-server/metrics-server:v0.5.0 –help
Conclusion
So go through the whole article to understand the use case and its requirement in detail. Once all the steps have been following given in the tutorial you will have good ideas about the installation and usage of Metrics Server in your Kubernetes application.
Recommended Articles
We hope that this EDUCBA information on “Kubernetes metrics server” was beneficial to you. You can view EDUCBA’s recommended articles for more information.