kubernetes hpa 无法获取 cpu 消费

kubernetes hpa cannot get cpu consumption

我正在尝试配置 kubernetes 水平 pod 自动缩放。我部署的定义是here

我开始 heapster 部署和 heapster 服务如下:

# kubectl run heapster --namespace=kube-system --image=gcr.io/google_containers/heapster:v1.0.2 --command -- /heapster --source=kubernetes:http://192.168.122.159:8080?inClusterConfig=false --sink=log
# kubectl expose deployment heapster --port=80 --target-port=8082 --name=heapster --namespace=kube-system

hpa 是这样创建的:

# kubectl autoscale deployment nginx-rc --max=5 --cpu-percent=25

heapster 似乎 运行 不错。这是 logs.

在这一切之后,hpa 没有收到任何关于 CPU 利用率的数据。

# kubectl describe hpa
Name:               nginx-rc
Namespace:          default
Labels:             <none>
Annotations:            <none>
CreationTimestamp:      Sat, 04 Jun 2016 07:23:03 -0400
Reference:          Deployment/nginx-rc/scale
Target CPU utilization:     25%
Current CPU utilization:    <unset>
Min replicas:           1
Max replicas:           5
Events:
  FirstSeen LastSeen    Count   From                SubobjectPath   Type        Reason          Message
  --------- --------    -----   ----                -------------   --------    ------          -------
  9m        7s      22  {horizontal-pod-autoscaler }            Warning     FailedGetMetrics    failed to get CPU consumption and request: metrics obtained for 0/1 of pods
  9m        7s      22  {horizontal-pod-autoscaler }            Warning     FailedComputeReplicas   failed to get CPU utilization: failed to get CPU consumption and request: metrics obtained for 0/1 of pods

控制器管理器日志中有一行重复出现:

Jun 04 07:21:33 master kube-controller-manager[8202]: W0604 07:21:33.079677    8202 horizontal.go:108] Failed to reconcile nginx-rc: failed to compute desired number of replicas based on CPU utilization for Deployment/default/nginx-rc: failed to get CPU utilization: failed to get CPU consumption and request: metrics obtained for 0/1 of pods

有人能指出问题的本质吗?

我怀疑这是因为您不是 运行 heapster 服务。 Horizo​​ntalPodAutoscaler 的指标客户端尝试从 kube-system 命名空间中名为 heapster 的服务获取指标。你可以看看默认的Heapster定义here.

如果这不是问题,请在主节点上查找 /var/log/kube-controller-manager。特别是,查找带有 failed to get pods metrics.

的条目

问题很可能是您的集群中没有 运行 DNS。

HPA 当前使用 heapster 服务名称来读取指标。您已正确创建它,但 HPA 控制器无法将服务名称解析为 IP 地址,因为您的集群中没有 DNS。

我已创建问题 https://github.com/kubernetes/kubernetes/issues/27044 以获得更多信息事件,这将有助于 user/admin 更好地理解问题。