kubernetes hpa无法获得cpu消费

时间:2016-06-04 13:50:15

标签: docker kubernetes autoscaling

我正在尝试配置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

有人可以在这里指出问题的本质吗?

2 个答案:

答案 0 :(得分:3)

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

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

我已创建问题https://github.com/kubernetes/kubernetes/issues/27044以提供更多信息性事件,以帮助用户/管理员更好地理解问题。

答案 1 :(得分:0)

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

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