Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Kubernetes Metrics API (Metrics Server)

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Monitoring Resource Metrics Pipeline Metrics API (Metrics Server)

Resource Indicator Pipeline:

Starting with Kubernetes 1.8, resource usage metrics, such as container CPU and memory usage, are available in Kubernetes through the Metrics API. These metrics can be accessed directly by the user, such as using the kubectl top command line, or they can be used by controllers in the cluster, such as Horizontal Pod Autoscaler, to make decisions; Metrics API:

Through the Metrics API, you can get the amount of resources currently used by a given node or pod. This API does not store metrics values, so it is impossible to get the resource usage of a given node 10 minutes ago; Metrics API repository:

API source code GitHub repository address: Metrics Server:

Metrics Server is an API Server. It provides the core Metrics API, collecting metrics information through the Metrics Server Kubernetes aggregator registered in the main API server, just like the k8s component kube-apiserver provides many API groups, but it is not part of k8s, but a single pod running on top of k8s;

In order for users to seamlessly use the APIs in Metrics Server, it is also necessary to aggregate such custom APIs into the core API group through aggregators, and then treat this API as part of the core API and view it directly through kubectl api-versions;

Metrics Server collects metrics data from the Summary API provided by kubelet on each node, i.e. port 10250. It collects metrics data of Node and Pod core resources, mainly memory and CPU usage, and stores the collected information in memory; you need to deploy it, otherwise it will not be available in the cluster.

The Metrics API requires Metrics Server to be deployed in the cluster. Otherwise it will not be available;

Deploying Metrics API (Metrics Server) in Kubernetes Cluster

k8s new generation architecture

Core metrics pipeline: Kubelet, metrics-server, api-server API components, statistics CPU cumulative utilization, real-time memory utilization, Pod resource utilization and container disk utilization;

Monitoring pipeline: Used to collect various metrics data from the system and provide end-users, storage systems, and HPA, which contain core metrics and many non-core metrics. Non-core metrics themselves cannot be resolved by k8s; deployment manual reference

Official site I refer to for deploying metrics-server Download yaml files required for deploying metrics server from official site

use for cyclic download [root@node1 metrics]#lltotal 24-rw-r--r--1 root 398 Feb 28 03:30 auth-delegate. yaml-rw-r--r--1 root root 419 Feb 28 03:30 auth-reader. yaml-rw-r--r--1 root 388 Feb 28 03:30 metrics-apisservice. yaml-rw-r--r--1 root 3252 Feb 28 03:30 metrics-server-deployment. yaml-rw-r--r--1 root 336 Feb 28 03:30 metrics-server-service. yaml-rw-r--r--1 root root 795 Feb 28 03:30 resource-reader. yaml [root@node1 metrics]#fix metrics-server-deployment. yaml file

Modify the custom variable resource limit in the container, otherwise it cannot run; command://modify here - /metrics-server - --metric-resolution=30s # These are needed for GKE, which doesn't support secure communication yet. # Remove these lines for non-GKE clusters, and when GKE supports token-based auth. - --kubelet-port=10250 #- --deprecated-kubelet-completely-insecure=true - - -kubelet-preferred-address-types = InternalIP, Hostname, InternalDNS, ExternalDNS, ExternalIPcommand://modify here - /pod_nanny - --config-dir=/etc/config - --cpu=5m - --extra-cpu=0.5m - --memory=80Mi - --extra-memory=8Mi - --threshold=5 - --deployment=metrics-server-v0.3.6 - --container=metrics-server - --poll-period=300000 - --estimator=exponential # Specifies the smallest cluster (defined in number of nodes) # resources will be scaled to. #---minClusterSize ={{metrics_server_min_cluster_size}} Modify the resource-reader. yaml file

Add nodes/statsrules: -apiGroups: -"" resources: -pods-nodes-namespaces-nodes/stats Download the image file in advance, on each node node

Reference script [root@node2~]#cat www.example.com #!/ bin/bash #docker pull www.example.com pull www.example.com tag www.example.com tag www.example.com rmi www.example.com rmi registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.8.7 [root@node2~]#Metrics Server Application Construction

non-repeatable build [root@node1 metrics]#kubectl apply-f./ clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator createdrolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader createdapiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io createdserviceaccount/metrics-server createdconfigmap/metrics-server-config createddeployment.apps/metrics-server-v0.3.6 createdservice/metrics-server createdclusterrole.rbac.authorization.k8s.io/system:metrics-server createdclusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created[root@node1 metrics]# [root@node1 ~]# kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGEmetrics-server-v0.3.6-cf56dfd4-mj7p2 2/2 Running 0 22 s test waiting for results

Sometimes you have to wait a while before you can swipe the data [root@node1~]#kubectl top nodesNAME CPU(cores) CPU% MEMORY(bytes) MEMORY% node1 137m 6% 1043Mi 69% node2 21m 2% 333Mi 20% node3 23m 2% 343Mi 28% access node resource information path via interface

View node resource metrics

[root@node1 metrics]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes" | jq | less

View pods resource metrics

[root@node1 metrics]# kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods" | jq | less

Other Ways to Deploy Metrics Server on Kubernetes

This method is much easier than the above deployment, and can be referred to

github kubernetes-sigs

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report