Kubernetes HPA无法读取GKE上的度量值(CPU利用率)
我正在一个集群上开发Google Kubernetes引擎。 群集会自动缩放节点数。 我已经创建了三个部署,并使用网站设置了自动伸缩策略(工作负载->部署->操作->自动伸缩),因此不需要手动编写YAML配置。 根据一位官员的说法,我没有犯任何错误 如果未指定请求,则可以仅基于 资源利用率的绝对值,例如 CPU利用率 以下是YAML的完整部署:Kubernetes HPA无法读取GKE上的度量值(CPU利用率),kubernetes,yaml,google-kubernetes-engine,gcloud,Kubernetes,Yaml,Google Kubernetes Engine,Gcloud,我正在一个集群上开发Google Kubernetes引擎。 群集会自动缩放节点数。 我已经创建了三个部署,并使用网站设置了自动伸缩策略(工作负载->部署->操作->自动伸缩),因此不需要手动编写YAML配置。 根据一位官员的说法,我没有犯任何错误 如果未指定请求,则可以仅基于 资源利用率的绝对值,例如 CPU利用率 以下是YAML的完整部署: apiVersion: apps/v1 kind: Deployment metadata: labels: app: student
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: student
name: student
namespace: ulibretto
spec:
replicas: 1
selector:
matchLabels:
app: student
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: student
spec:
containers:
- env:
- name: CLUSTER_HOST
valueFrom:
configMapKeyRef:
key: CLUSTER_HOST
name: shared-env-vars
- name: BIND_HOST
valueFrom:
configMapKeyRef:
key: BIND_HOST
name: shared-env-vars
- name: TOKEN_TIMEOUT
valueFrom:
configMapKeyRef:
key: TOKEN_TIMEOUT
name: shared-env-vars
image: gcr.io/ulibretto/github.com/ulibretto/studentservice
imagePullPolicy: IfNotPresent
name: studentservice-1
---
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
labels:
app: student
name: student-hpa-n3bp
namespace: ulibretto
spec:
maxReplicas: 100
metrics:
- resource:
name: cpu
targetAverageUtilization: 80
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: student
---
apiVersion: v1
kind: Service
metadata:
annotations:
cloud.google.com/neg: '{"ingress":true}'
labels:
app: student
name: student-ingress
namespace: ulibretto
spec:
clusterIP: 10.44.5.59
ports:
- port: 5000
protocol: TCP
targetPort: 5000
selector:
app: student
sessionAffinity: None
type: ClusterIP
问题是HPA看不到指标(平均CPU利用率),这真的很奇怪(见图)。
我缺少什么?编辑 你说得对。正如我前面提到的,您不需要在
scaleTargetRef:
中指定名称空间:ulibretto
由于您提供了所有YAML,我能够找到适当的根本原因
如果您进行检查,您将在代码中找到注释
resources:
# You must specify requests for CPU to autoscale
# based on CPU utilization
requests:
cpu: "250m"
您的部署没有指定资源请求
。我尝试过这个(我删除了一些部分,因为我无法部署您的容器,并在HPA中更改了apiVersion):
如果要使用CLI创建HPA,请使用相同的情况:
$ kubectl autoscale deployment student -n ulibretto --cpu-percent=50 --min=1 --max=100
horizontalpodautoscaler.autoscaling/student autoscaled
$ kubectl get hpa -n ulibretto
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
student Deployment/student <unknown>/50% 1 100 0 3s
请参阅第一篇文章:我刚刚更新了YAML配置。我试过了,但是如果我使用“autoscaling/v1”(我在您共享的链接上使用了示例conf)和“autoscaling/v2beta1”(由GCloud中的UI自动创建的版本),那么“namespace”似乎是一个未知字段。无论如何,要查看自动缩放,我必须将“kubectl get hpa--namespace”称为“ulibretto”,因为它不存在于默认名称空间中。这是我的错误。我将在几分钟内编辑这个答案。好吧,GKE文档也说:。这就是为什么我没有写部署请求(也是因为我无法估计,我是一个新手,因为你救了我。非常感谢你花时间帮助我。
$ kubectl get all -n ulibretto
NAME READY STATUS RESTARTS AGE
pod/student-6f797d5888-84xfq 1/1 Running 0 95s
pod/student-6f797d5888-b7ctq 1/1 Running 0 95s
pod/student-6f797d5888-fbtmd 1/1 Running 0 95s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/student 3/3 3 3 95s
NAME DESIRED CURRENT READY AGE
replicaset.apps/student-6f797d5888 3 3 3 95s
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
horizontalpodautoscaler.autoscaling/student-hpa Deployment/student 0%/80% 1 100 3 95s
$ kubectl autoscale deployment student -n ulibretto --cpu-percent=50 --min=1 --max=100
horizontalpodautoscaler.autoscaling/student autoscaled
$ kubectl get hpa -n ulibretto
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
student Deployment/student <unknown>/50% 1 100 0 3s
$ kubectl get all -n ulibretto
NAME READY STATUS RESTARTS AGE
pod/student-6f797d5888-84xfq 1/1 Running 0 4m4s
pod/student-6f797d5888-b7ctq 1/1 Running 0 4m4s
pod/student-6f797d5888-fbtmd 1/1 Running 0 4m4s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/student 3/3 3 3 4m5s
NAME DESIRED CURRENT READY AGE
replicaset.apps/student-6f797d5888 3 3 3 4m5s
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
horizontalpodautoscaler.autoscaling/student Deployment/student 0%/50% 1 100 3 58s