k8s1.18.2部署Metrics-Server监控服务

Metrics-Server概念介绍

Metrics-Server是集群核心监控数据的聚合器,在k8s早期版本中,对资源的监控使用的是heapster的资源监控工具。但是从 Kubernetes 1.8 开始,Kubernetes 通过 Metrics API 获取资源使用指标,例如容器 CPU 和内存使用情况。这些度量指标可以由用户直接访问,例如通过使用kubectl top 命令,或者使用集群中的控制器,,因为k8s的api-server将所有的数据持久化到了etcd中,显然k8s本身不能处理这种频率的采集,而且这种监控数据变化快且都是临时数据,因此需要有一个组件单独处理他们.

1.下载并解压Metrics-Server

[root@master-11 ~]# wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
[root@master-11 ~]# tar -zxvf v0.3.6.tar.gz

2.修改配置文件

[root@master-11 ~]# cd metrics-server-0.3.6/deploy/1.8+
[root@master-11 1.8+]# sed -i 's#k8s.gcr.io/metrics-server-amd64:v0.3.6#mirrorgooglecontainers/metrics-server-amd64:v0.3.6#g' metrics-server-deployment.yaml
[root@master-11 1.8+]# sed -i 's/Always/IfNotPresent/g' metrics-server-deployment.yaml 

3.安装Metrics-Server

[root@master-11 1.8+]# kubectl apply -f .
clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.apps/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created

4.查看创建的相关Metrics-Server组件

[root@master-11 1.8+]# kubectl get deployments.apps,svc,pods -n kube-system  | grep metrics
deployment.apps/metrics-server            1/1     1            1           81s
service/metrics-server   ClusterIP   10.103.252.240           443/TCP                  81s
pod/metrics-server-57bc7f4584-zkbqz            1/1     Running   0          81s

5.查看pod和node的资源使用情况

使用kubectl top命令

[root@master-11 1.8+]# kubectl top nodes
NAME        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
master-11   169m         4%     1651Mi          28%       
node1-12    102m         2%     552Mi           14%       
node2-13    93m          2%     533Mi           14%     
[root@master-11 1.8+]# kubectl top pods -n kube-system 
NAME                                       CPU(cores)   MEMORY(bytes)   
calico-kube-controllers-578894d4cd-k4ccx   2m           26Mi            
calico-node-4svc2                          15m          81Mi            
calico-node-r8xlx                          21m          29Mi            
calico-node-vvksl                          23m          44Mi            
coredns-7ff77c879f-sz87s                   2m           14Mi            
coredns-7ff77c879f-v8vg8                   2m           16Mi            
etcd-master-11                             15m          146Mi           
kube-apiserver-master-11                   26m          490Mi           
kube-controller-manager-master-11          10m          41Mi            
kube-proxy-4q2fg                           1m           26Mi            
kube-proxy-fpn7d                           1m           8Mi             
kube-proxy-mvwf7                           1m           12Mi            
kube-scheduler-master-11                   3m           15Mi            
metrics-server-57bc7f4584-zkbqz            2m           10Mi    

你可能感兴趣的:(k8s1.18.2部署Metrics-Server监控服务)