【K8S 三】部署 metrics-server 插件

目录

Metrics Server

安装前提

下载镜像并配置启动YAML

 部署并验证


这篇文章写得比较早,当时是在kubeadm部署环境下实施的,如果您是通过二进制部署(因为这种部署拓扑比较灵活)出现了问题可以移步《【K8S 七】Metrics Server部署中的问题》,可能会对您有帮助。

Metrics Server

Metrics Server是一种可伸缩的、高效的容器资源指标源,用于Kubernetes内置的自动缩放管道。

Metrics服务器从Kubelets收集资源指标,并通过Metrics API在Kubernetes apiserver中公开它们,以便HPA(Horizontal Pod Autoscaler)和VPA(Vertical Pod Autoscaler)使用。Metrics API也可以被kubectl top访问,这使得它更容易调试弹性伸缩管道。

Metrics服务器并不用于非弹性伸缩的目的。例如,不要使用它将指标转发到监视解决方案,或者将其作为监视解决方案指标的来源。

Horizontal Pod Autoscaler:水平Pod弹性伸缩;Vertical Pod Autoscaler:垂直Pod弹性伸缩。

 资源消耗:Metrics Server uses 1m core of CPU and 3 MB of memory per node

 可扩展支持最多5,000个节点集群

详情参考kubernetes-sigs/metrics-server 

安装前提

下面所有操作的前提是已经存在搭建好的Kubernetes集群环境,且apiserver要配置证书,且metrics-server也需要CA证书,不然就会报错(使用kubeadm工具会简单很多):

 Expected to load root CA config from /var/run/secrets/kubernetes.io/serviceaccount/ca.crt, but got err: open /var/run/secrets/kubernetes.io/serviceaccount/ca.crt: no such file or directory
Error: unable to load configmap based request-header-client-ca-file: Get "https://10.254.0.1:443/api/v1/namespaces/kube-system/configmaps/extension-apiserver-authentication": x509: certificate signed by unknown authority

下载镜像并配置启动YAML

目前Metrics-Server的镜像是k8s.gcr.io/metrics-server/metrics-server:v0.4.1,无法科学上网的同学,只能曲线救国,手动下载镜像到本地或推到私有镜像库:

本人已经将镜像推到了实验环境的私有仓库中:192.168.x.x/library/metrics-server:v0.4.1

下载启动配置文件,并对文件进行如下配置,否则metrics-server启动会报错:

unable to fully scrape metrics from node kubeadmin-node: unable to fetch metrics from node kubeadmin-node: Get "https://192.168.x.x:10250/stats/summary?only_cpu_and_memory=true": x509: cannot validate certificate for 192.168.x.x because it doesn't contain any IP SANs, unable to fully scrape metrics from node rhel-8-11.8: unable to fetch metrics from node rhel-8-11.8: Get "https://192.168.x.y:10250/stats/summary?only_cpu_and_memory=true": x509: cannot validate certificate for 192.168.x.y because it doesn't contain any IP SANs

wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
cp components.yaml kube-metric-server.yaml
diff components.yaml kube-metric-server.yaml 
133a134,135
>         - --metric-resolution=30s
>         - --kubelet-insecure-tls
136c138
<         image: k8s.gcr.io/metrics-server/metrics-server:v0.6.1
---
>         image: registry.aliyuncs.com/google_containers/metrics-server:v0.6.1

 部署并验证

$ kubectl apply -f kube-metrics-server.yaml
$ kubectl get po -o wide -n kube-system
NAME                                  READY   STATUS    RESTARTS   AGE     IP              NODE             NOMINATED NODE   READINESS GATES
metrics-server-6695c86795-gfkhh       1/1     Running   0          58m     172.254.1.14    kubeadmin-node              


$ kubectl top node
NAME             CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
kubeadmin-node   57m          0%     2085Mi          27%       
rhel-8-11.8      126m         1%     1714Mi          22%       
$ kubectl top pod
mysql-gbprd              1m           467Mi           
myweb-5478cb4767-gm5k2   1m           195Mi           
myweb-5478cb4767-h5snw   1m           195Mi

你可能感兴趣的:(云计算-容器云,kubernetes,metrics)