我正在尝试为我的AKS群集设置HPA。以下是Kubernetes清单文件:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: XXXXXX\tools\kompose.exe
convert
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: loginservicedapr
name: loginservicedapr
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: loginservicedapr
strategy: {}
template:
metadata:
annotations:
kompose.cmd: XXXXXX\kompose.exe
convert
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: loginservicedapr
spec:
containers:
image: XXXXXXX.azurecr.io/loginservicedapr:latest
imagePullPolicy: ""
name: loginservicedapr
resources:
requests:
cpu: 250m
limits:
cpu: 500m
ports:
- containerPort: 80
resources: {}
restartPolicy: Always
serviceAccountName: ""
volumes: null
status: {}
---
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: XXXXXXXXXX\kompose.exe
convert
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: loginservicedapr
name: loginservicedapr
spec:
type: LoadBalancer
ports:
- name: "5016"
port: 5016
targetPort: 80
selector:
io.kompose.service: loginservicedapr
status:
loadBalancer: {}
以下是我的HPA yaml文件:
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: loginservicedapr-hpa
spec:
maxReplicas: 10 # define max replica count
minReplicas: 3 # define min replica count
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: loginservicedapr
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
- type: Pods
pods:
name: cpu
target:
type: Utilization
averageUtilization: 50
但是当HPA出现错误'FailedGetResourceMetric‘- 'missing request for CPU’时。
我还使用以下语句安装了metrics-server (尽管不确定是否需要):kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
但是,当我执行'kubectl describe‘时,我仍然得到以下输出:
Name: loginservicedapr-hpa
Namespace: default
Labels: fluxcd.io/sync-gc-mark=sha256.Y6dHhIOs-hNYbDmJ25Ijw1YsJ_8f0PH3Vlruj5rfbFk
Annotations: fluxcd.io/sync-checksum: d5c0d9eda6db0c40f1e5e23e1356d0268dbccc8f
kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"autoscaling/v1","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{"fluxcd.io/sync-checksum":"d5c0d9eda6db0c40f1e5...
CreationTimestamp: Wed, 08 Jul 2020 17:19:47 +0530
Reference: Deployment/loginservicedapr
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): <unknown> / 50%
Min replicas: 3
Max replicas: 10
Deployment pods: 3 current / 3 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale True SucceededGetScale the HPA controller was able to get the target's current scale
ScalingActive False FailedGetResourceMetric the HPA was unable to compute the replica count: missing request for cpu
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedComputeMetricsReplicas 33m (x1234 over 6h3m) horizontal-pod-autoscaler Invalid metrics (1 invalid out of 1), last error was: failed to get cpu utilization: missing request for cpu
Warning FailedGetResourceMetric 3m11s (x1340 over 6h3m) horizontal-pod-autoscaler missing request for cpu
我还有另外两个服务和“loginservicedapr”一起部署。但我还没有为这些服务编写HPA。但我也在他们的YAML文件中包含了这些服务的资源限制。如何让这个HPA发挥作用?
发布于 2020-07-09 02:25:04
resources
在您的pod规范中出现两次。
resources: # once here
requests:
cpu: 250m
limits:
cpu: 500m
ports:
- containerPort: 80
resources: {} # another here, clearing it
发布于 2020-07-09 12:38:35
我在kubernetes清单文件中更改了以下内容,从而解决了这个问题:
resources:
requests:
cpu: 250m
limits:
cpu: 500m
设置为以下内容:
resources:
requests:
cpu: "250m"
limits:
cpu: "500m"
在那之后,HPA起作用了。以下是提供解决方案的GitHub链接:https://github.com/kubernetes-sigs/metrics-server/issues/237,但我没有添加任何内部IP地址命令或其他任何内容。
发布于 2020-07-09 04:12:52
这通常与指标服务器相关。
确保您没有看到有关metrics服务器安装的任何异常:
# This should show you metrics (they come from the metrics server)
$ kubectl top pods
$ kubectl top nodes
或者查看日志:
$ kubectl logs <metrics-server-pod>
另外,检查您的kube-controller-manager日志中是否有与HPA事件相关的条目。
此外,如果您想了解更多关于您的pod是否缺少请求/限制的信息,您可以简单地查看由HPA管理的运行pod的完整输出:
$ kubectl get pod <pod-name> -o=yaml
其他一些人则幸运地使用了deleting and renaming the HPA too。
https://stackoverflow.com/questions/62800892
复制相似问题