Kubernetes监控:MetricsServer部署方法

Kubernetes监控:MetricsServer部署方法

2023年6月30日发(作者:)

Kubernetes监控:MetricsServer部署⽅法从kubernetes 1.8的版本开始,随着横向扩缩容功能的稳定和提升,HPA⽀持⾃定义指标,Cluster Autoscaler提升了性能与错误报告能⼒; ⽀持新版的HPA API,相关的API和组件升⾄稳定版本,⽐如: resource Metrics API、custom metrics API和metrics-server等。这意味着Metrics Server已经开始使⽤了。这篇⽂章介绍⼀下Metrics Server在Kubernetes上的部署⽅法。Metrics API vs Metrics ServerMetrics API诸如CPU和内存使⽤率等资源使⽤率指标都可以通过Metrics API来获取。⽤户可以直接通过kubectl top命令等⽅式直接获取这些指标信息(⽐如node和pod相关的指标信息)。虽然通过Metrics API可以获得node或者pod的资源使⽤量的信息,但是API并不会保存这些指标的数据,所以在指定的保存期间之外的时间的数据⽆法获取,只能结合时序列数据库来进⾏保存。API Endpoint: /apis//注意事项:API的使⽤需要集群部署Metrics Server,否则⽆法获取。Metrics ServerMetrics Server可以⽤来在集群范围可以进⾏资源使⽤状况信息的收集,它通过Kubelet收集在各个节点上提供的指标信息,MetricsServer的使⽤需要开启聚合层,所以需要在Api Server的启动选项中添加如下内容: --requestheader-client-ca-file={{ var_ssl_ca_dir }}/{{ var_ssl_file_ca_pem }} --requestheader-allowed-names= --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --proxy-client-cert-file={{ var_ssl_k8s_dir }}/{{ var_ssl_aggregator_cert_prefix }}.pem --proxy-client-key-file={{ var_ssl_k8s_dir }}/{{ var_ssl_aggregator_cert_prefix }}- --enable-aggregator-routing=true注意事项:requestheader-allowed-names:如果不为空的情况下,需要保证此设定值与证书中的CN⼀致enable-aggregator-routing:master节点上没有kube-proxy时,需要设定为true部署事前准备Kubernetes 1.17.2,可参看下⽂进⾏快速环境搭建:[root@host131 ansible]# kubectl get node -o wideNAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME192.168.163.131 Ready 54s v1.17.2 192.168.163.131 CentOS Linux 7 (Core) 7.x86_64 docker://19.3.5[root@host131 ansible]#

Metrics Server安装前确认可以看到kubectl top命令⽆法使⽤,因为此命令的正常使⽤需要metrics server的运⾏。[root@host131 ansible]# kubectl top nodeError from server (NotFound): the server could not find the requested resource (get services http:heapster:)[root@host131 ansible]#

[root@host131 ansible]# kubectl top podError from server (NotFound): the server could not find the requested resource (get services http:heapster:)[root@host131 ansible]#

步骤1: git clone[root@host131 ~]# git clone /kubernetes-incubator/metrics-serverCloning into 'metrics-server'...remote: Enumerating objects: 29, : Counting objects: 100% (29/29), : Compressing objects: 100% (20/20), : Total 11484 (delta 10), reused 23 (delta 9), pack-reused 11455Receiving objects: 100% (11484/11484), 12.24 MiB | 1.06 MiB/s, ing deltas: 100% (5982/5982), done.[root@host131 ~]#

步骤2: 设定启动选项进⼊到deploy/1.8+的⽬录下,根据需要修改如下设定⽂件():[root@host131 ~]# cd metrics-server/deploy/1.8+/[root@host131 1.8+]# [root@host131 1.8+]# ls -l

-rw-r--r-- 1 root root 1183 Jan 31 17:50 [root@host131 1.8+]#

进⾏如下修改[root@host131 1.8+]# cp -p [root@host131 1.8+]# vi [root@host131 1.8+]# diff 44c44< imagePullPolicy: IfNotPresent---> imagePullPolicy: Always[root@host131 1.8+]#保证本地存在metrics-server的镜像[root@host131 1.8+]# grep image: image: /metrics-server-amd64:v0.3.6[root@host131 1.8+]# docker images |grep /metrics-server-amd64 v0.3.6 9dd718864ce6 3 months ago 39.9MB[root@host131 1.8+]#

注:直接可以获取镜像的情况下可以直接忽略此配置和设定步骤3: 启动Metrics Server执⾏命令:kubectl create -f .[root@host131 1.8+]# pwd/root/metrics-server/deploy/1.8+[root@host131 1.8+]# kubectl create -f ./system:aggregated-metrics-reader /metrics-server:system:auth-delegator /metrics-server-auth-reader / createdserviceaccount/metrics-server /metrics-server createdservice/metrics-server /system:metrics-server /system:metrics-server created[root@host131 1.8+]#步骤4: 启动确认确认pod、deployment和服务的运⾏状况[root@host131 1.8+]# kubectl get pod -A |grep metricskube-system metrics-server-5cc8d5c4df-ms2ts 1/1 Running 0 31s[root@host131 1.8+]# kubectl get deployment -A |grep metricskube-system metrics-server 1/1 1 1 40s[root@host131 1.8+]# kubectl get service -A |grep metricskube-system metrics-server ClusterIP 10.254.197.79 443/TCP 47s[root@host131 1.8+]#使⽤kubectl top确认pod资源信息[root@host131 1.8+]# kubectl top pod[root@host131 1.8+]# kubectl top pod metrics-server-5cc8d5c4df-ms2ts -n kube-systemNAME CPU(cores) MEMORY(bytes)

metrics-server-5cc8d5c4df-ms2ts 1m 12Mi

[root@host131 1.8+]#

使⽤kubectl top确认node资源信息需要稍等⼀点时间等待信息的收集,否则可能会有如下提⽰信息[root@host131 1.8+]# kubectl top nodeerror: metrics not available yet[root@host131 1.8+]#

稍等⼀点时间就可以看到node资源的信息显⽰了[root@host131 1.8+]# kubectl top nodeNAME CPU(cores) CPU% MEMORY(bytes) MEMORY%

192.168.163.131 96m 9% 2534Mi 65%

[root@host131 1.8+]#

常见问题参考内容

发布者:admin,转转请注明出处:http://www.yc00.com/news/1688056839a72350.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信