gpt4 book ai didi

kubernetes - 如何使用指标服务器而不是堆积器查看HPA中的CPU使用率

转载 作者:行者123 更新时间:2023-12-02 12:37:30 26 4
gpt4 key购买 nike

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

# kubectl top nodes

error: metrics not available yet


# kubectl get pods -n kube-system

NAME READY STATUS RESTARTS AGE

heapster-709db6bd48-f2gba 2/2 Running 0 6h

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

.....


# kubectl get hpa

NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE

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

最佳答案

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

-删除指标服务器

-changemetrics-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

再次应用指标服务器文件: 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 created apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created 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值。

关于kubernetes - 如何使用指标服务器而不是堆积器查看HPA中的CPU使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54452475/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com