K8S部署Metrics-Server

下载解压进入目录 修改配置文件

wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
cd metrics-server-0.3.6/deploy/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: mirrorgooglecontainers/metrics-server-amd64:v0.3.6         #修改镜像地址
        imagePullPolicy: IfNotPresent   #拉取镜像策略
        # 修改镜像启动命令  忽略ssl
        command:
        - /metrics-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

执行安装

    kubectl apply -f  metrics-server-0.3.6/deploy/1.8+/
    kubectl get pod -n kube-system     
    metrics-server-6bfbbcff4d-trldc        1/1     Running   0          11m

查看结果

kubectl top node
NAME           CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master01   271m         6%     3945Mi          51%       
k8s-master02   202m         5%     2015Mi          26%       
k8s-master03   168m         4%     2106Mi          27%       
k8s-node1      84m          4%     661Mi           38%

如果执行kubectl top node的时候报 error: metrics not available yet 那就再等一会,服务正在启动中


参考链接: https://blog.csdn.net/jiangbb8686/article/details/100358791

https://www.cnblogs.com/binghe001/p/12821804.html

发表评论