kubernetes1.18安装metrics-server服务

在新版的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]# mkdir metric-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%    

 

上一篇:javascript技巧大全套


下一篇:AndroidStudio 3.3+ ButterKnife R2 红名问题