kubernetes1.18安裝metrics-server服務
阿新 • • 發佈:2021-06-30
在新版的K8S中,系統資源的採集均使用Metrics-Server服務,可以通過Metrics-Server服務採集節點和Pod的記憶體、磁碟、CPU和網路的使用率等資訊。通過 Metrics API 獲取。
- Metrics API 只可以查詢當前的度量資料,並不儲存歷史資料
- Metrics API URI 為
/apis/metrics.k8s.io/
,在k8s.io/metrics維護 - 必須部署 metrics-server 才能使用該 API,metrics-server 通過呼叫 Kubelet Summary API 獲取資料
1、下載mertric-server
[root@master69 kubernetes]# mkdirmetric-server
[root@master69 kubernetes]# cd metric-server/[root@master69 metric-server]# wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
2、解壓
[root@master69 metric-server]# tar -zxvf v0.3.6.tar.gz
3、修改metrics-server-deployment.yaml檔案配置
[root@master69 metric-server]# cd metrics-server-0.3.6/deploy/1.8+/ [root@master69 1.8+]# vim metrics-server-deployment.yaml
--- apiVersion: v1 kind: ServiceAccount metadata: name: metrics-server namespace: kube-system --- apiVersion: apps/v1 kind: Deployment metadata: name: metrics-server namespace: kube-system labels: k8s-app: metrics-server spec: selector: matchLabels: k8s-app: metrics-server template: metadata: name: metrics-server labels: k8s-app: metrics-server spec: serviceAccountName: metrics-server volumes: # mount in tmp so we can safely use from-scratch images and/or read-only containers - name: tmp-dir emptyDir: {} containers: - name: metrics-server #image: k8s.gcr.io/metrics-server-amd64:v0.3.6 image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6 #修改image倉庫和映象拉取策略 imagePullPolicy: IfNotPresent #增加Command配置 command: - /metric-server - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalDNS,InternalIP,ExternalDNS,ExternalIP,Hostname volumeMounts: - name: tmp-dir mountPath: /tmp #增加resources配置 resources: limits: cpu: 300m memory: 200Mi requests: cpu: 200m memory: 100Mi
4、安裝metric-server
[root@master69 1.8+]# kubectl create -f .
5、測試
[root@master69 1.8+]# kubectl top node NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% master69 355m 8% 3600Mi 45% redis-01.hlqxt 105m 2% 12396Mi 38% redis-02.hlqxt 117m 2% 19301Mi 60% redis-03.hlqxt 99m 2% 15405Mi 48%