【发布时间】:2020-04-14 07:30:22
【问题描述】:
我正在尝试部署自己的 HPA,但没有成功。 尽管在尝试部署 Kubernetes 的官方 PHP 时,它按计划工作。 当我尝试使用 HPA 部署自己的测试部署时,它不起作用。
比较 2 个 HPA 部署流程 - Kubernetes 官方部署 VS My Test 部署:
部署官方 Kubernetes 模板镜像:
$ kubectl run php-apache --image=gcr.io/google_containers/hpa-example --requests=cpu=200m --expose --port=80
service "php-apache" created
deployment "php-apache" created
我自己的测试部署结果
{
"apiVersion": "autoscaling/v1",
"kind": "HorizontalPodAutoscaler",
"metadata": {
"annotations": {
"autoscaling.alpha.kubernetes.io/conditions": "[{\"type\":\"AbleToScale\",\"status\":\"False\",\"lastTransitionTime\":\"2019-12-22T20:39:59Z\",\"reason\":\"FailedGetScale\",\"message\":\"the HPA controller was unable to get the target's current scale: deployments/scale.apps \\\"gw-autoscale-t6\\\" not found\"}]"
},
"creationTimestamp": "2019-12-22T20:39:44Z",
"labels": {
"app": "gw-autoscale-t6"
},
"name": "gw-autoscale-t6",
"namespace": "dev",
"resourceVersion": "17299134",
"selfLink": "/apis/autoscaling/v1/namespaces/dev/horizontalpodautoscalers/gw-autoscale-t6",
"uid": "2f7e014c-24fb-11ea-a4d8-a28620329da6"
},
"spec": {
"maxReplicas": 3,
"minReplicas": 1,
"scaleTargetRef": {
"apiVersion": "apps/v1",
"kind": "Deployment",
"name": "gw-autoscale-t6"
},
"targetCPUUtilizationPercentage": 80
},
"status": {
"currentReplicas": 0,
"desiredReplicas": 0
}
}
我用于上述两个部署的 HPA 部署 yaml (官方部署和我的测试部署):
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Values.name }}
labels:
app: {{ .Values.name }}
namespace: {{ .Values.namespace }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.name }}
minReplicas: {{ .Values.spec.replicaCountMin }}
maxReplicas: {{ .Values.spec.replicaCountMax }}
targetCPUUtilizationPercentage: 50
selector:
matchLabels:
app: {{ .Values.name }}
template:
metadata:
labels:
app: {{ .Values.name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
结果:
PHP HPA 正在按计划工作
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
php-apache Deployment/php-apache 0%/50% 1 3 1 3d7h
测试部署 HPA 不起作用
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
gw-autoscale-t6 Deployment/gw-autoscale-t6 <unknown>/80% 1 3 0 11m
测试部署 HPA 错误
Name: gw-autoscale-t6
Namespace: dev
Labels: app=gw-autoscale-t6
Annotations: <none>
CreationTimestamp: Sun, 22 Dec 2019 22:39:44 +0200
Reference: Deployment/gw-autoscale-t6
Metrics: ( current / target )
resource cpu on pods (as a percentage of request): <unknown> / 80%
Min replicas: 1
Max replicas: 3
Deployment pods: 0 current / 0 desired
Conditions:
Type Status Reason Message
---- ------ ------ -------
AbleToScale False FailedGetScale the HPA controller was unable to get the target's current scale: deployments/scale.apps "gw-autoscale-t6" not found
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedGetScale 27s (x81 over 20m) horizontal-pod-autoscaler deployments/scale.apps "gw-autoscale-t6" not found
-
我也尝试了很多其他类型的部署文件。
-
我的 Metrics-Service 已安装。
-
我正在使用 Helm 安装我的部署。
我该怎么做才能解决这个问题?
我找到的解决方案是将“资源”属性添加到测试部署 yaml 文件中:
例如:如果按 cpu 使用量进行缩放,请按照部署文件中的说明使用。
resources:
requests:
cpu: {{ .Values.request.cpu }}
limits:
cpu: {{ .Values.limits.cpu }}
【问题讨论】:
-
可能是你的部署有问题,可以在这里添加你的部署yaml吗?还要检查 HPA API,有些字段在规范下不存在,在应用时会失败,并要求您每次都使用
--validate=false标志。但目前的问题仍然可能是您的副本集部署 yaml 可能缺少几个字段。 -
您在 Default 命名空间中尝试过官方 PHP 是否正确?
-
@BinaryBullet 我在主帖中添加了部署 Json。我相信我也尝试过其他几种 apiVersion / kind。当前的 Json 中是否缺少某些内容?
-
@Nick 官方 PHP 在另一个命名空间 (dev) 中运行。我看不到在提到的链接(github.com/kubernetes/kubernetes/issues/79365)中有一个实际可靠的答案,或者我只是错过了一些东西。
标签: node.js kubernetes kubernetes-helm kubectl