如何使用metrics-server而不是heapster来查看HPA中的CPU使用情况

问题描述 投票:1回答:1

如何设置使用metrics-server来获取HPA的CPU使用率?

# kubectl top nodes

错误:指标尚不可用

# kubectl get pods -n kube-system

NAME READY STATUS RESTARTS AGE

heapster-709db6bd48-f2gba 2/2运行0 6h

metrics-server-70647b8f8b-99pja 1/1运行0 5h

.....

# kubectl get hpa

名称参考目标MINIPODS MAXPODS REPLICAS AGE

devops-deployment部署/ devops-deployment <unknown> / 50%4 10 4 1h

kubernetes cpu-usage missing-data autoscaling azure-kubernetes
1个回答
0
投票

我和你有同样的问题。帮助我的是this post

- 删除指标 - 服务器

-change metrics-server / deploy / 1.8 + / metrics-server-deployment.yaml

- 再来一次

- 或者简单

更多详情:

kubectl delete -f metrics-server/deploy/1.8+

编辑metrics-server/deploy/1.8+/metrics-server-deployment.yaml并添加下一个选项:

    command:
    - /metrics-server
    - --kubelet-insecure-tls
    - --kubelet-preferred-address-types=InternalIP

metrics-server-deployment.yaml应该如下所示,或者只是从here复制粘贴它

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: metrics-server
  namespace: kube-system
---
apiVersion: extensions/v1beta1
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.1
        imagePullPolicy: Always
        command:
        - /metrics-server
        - --kubelet-insecure-tls
        - --kubelet-preferred-address-types=InternalIP
        volumeMounts:
        - name: tmp-dir
          mountPath: /tmp

再次应用metrics-server文件:kubectl apply -f metrics-server/deploy/1.8+

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创建了apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io创建了serviceaccount / metrics-server created deployment.extensions / 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

并检查结果:

kubectl get hpa    
NAME               REFERENCE                     TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
nginx-deployment   Deployment/nginx-deployment   <unknown>/80%   3         10        10         25

kubectl top nodes
NAME            CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
kube-master-1   255m         12%    2582Mi          35%       
kube-worker-1   124m         6%     2046Mi          27

kubectl top pods
NAME                                CPU(cores)   MEMORY(bytes)   
nginx-deployment-76bf4969df-4bbdc   0m           2Mi             
nginx-deployment-76bf4969df-5m6xc   0m           2Mi             
nginx-deployment-76bf4969df-b4zh7   0m           2Mi             
nginx-deployment-76bf4969df-c58wl   0m           2Mi             
nginx-deployment-76bf4969df-cktcg   0m           2Mi             
nginx-deployment-76bf4969df-fbjj9   0m           2Mi             
nginx-deployment-76bf4969df-gh94w   0m           2Mi             
nginx-deployment-76bf4969df-qx6ld   0m           2Mi             
nginx-deployment-76bf4969df-rvt54   0m           2Mi             
nginx-deployment-76bf4969df-vq9gs   0m           2Mi

此外,如果基于资源利用率百分比在容器上使用自动缩放,则容器需要提供资源限制,否则将无法计算正在使用的资源百分比。如果部署的pod规范没有资源限制,则需要将HPA设置为基于绝对值进行缩放,并包含单位。在CPU的情况下,您可以将其设置为300m作为字符串。例如,在RAM的情况下,您可以将其设置为400Mi。缺少资源限制可以解释为什么在current下运行kubectl get hpa时没有看到度量标准的TARGETS值。

© www.soinside.com 2019 - 2024. All rights reserved.