K8S部署Metrics-Server服务

1.下载并解压Metrics-Server

https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
tar -zxvf v0.3.6.tar.gz 

2.修改Metrics-Server配置文件

cd metrics-server-0.3.6/deploy/1.8+/
vim metrics-server-deployment.yaml

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 和 imagePullPolicy
        image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6
        imagePullPolicy: IfNotPresent
        # 新增command配置
        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  

3.安装Metrics-Server

kubectl apply -f metrics-server-0.3.6/deploy/1.8+/

4.查看node信息

[root@binghe101 ~]# kubectl top node
NAME        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
binghe101   141m         7%     1113Mi          65%       
binghe102   62m          3%     549Mi           32% 
binghe103   100m         5%     832Mi           48%

 5、测试HPA

1)、创建部署deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
     matchLabels:
       app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: docker.io/nginx
        ports:
        - containerPort: 80
        resources:
          limits:
             cpu: 500m
          requests:
             cpu: 500m 

2)、设定自动扩容的条件

kubectl autoscale deployment hpa-demo --cpu-percent=10 --min=1 --max=10

 --cpu-percent=10      cpu使用率超过10%

3)、使用ab工具进行压测

ab -c 5000 -n 2000000 http://10.244.1.10:80/

10.244.1.10  ---为pod的ip

4)、发现pod数量会增长

上一篇:kudu 监控


下一篇:[问题已处理]-k8s升级版本之后kubectl返回很慢