首页 > 解决方案 > Kubernetes 自动缩放

问题描述

我的集群上安装了 Kubernetes v1.12.1。我从以下 repo 下载了 metrics-server: https ://github.com/kubernetes-incubator/metrics-server

然后运行以下命令:

kubectl create -f metrics-server/deploy/1.8+/

然后我尝试使用以下方法自动缩放部署:

kubectl autoscale deployment example-app-tier --min 1 --max 3 --cpu-percent 70 --spacename example

但这里的目标显示未知/70%

kubectl get hpa --spacename example
NAMESPACE   NAME               REFERENCE                     TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
example example-app-tier   Deployment/example-app-tier   <unknown>/70%   1         3         1          3h35m

当我尝试运行 kubectl 顶级节点或 pod 时,我收到一条错误消息:

error: Metrics not available for pod default/pi-ss8j6, age: 282h48m5.334137739s

因此,我正在寻找任何可以帮助我逐步使用 metrics-server 或 Prometheus 启用自动缩放的教程(而不是 Heapster,因为它已被弃用并且不再受支持)

谢谢!

标签: kubernetesprometheusautoscaling

解决方案


您需要向 API 服务器注册您的指标服务器并确保它们能够通信。

https://github.com/kubernetes/kubernetes/issues/59438

如果已经完成,您需要查看 k8s 版本中 kubectl top 命令的帮助,该命令可能默认使用 heapster ,您可能需要告诉它使用新服务。

https://github.com/kubernetes/kubernetes/pull/56206

从帮助命令看来,它尚未移植到新的度量服务器,并且默认情况下仍在寻找 heapster。

C02W84XMHTD5:tmp iahmad$ kubectl top node --help
Display Resource (CPU/Memory/Storage) usage of nodes. 

The top-node command allows you to see the resource consumption of nodes.

Aliases:
node, nodes, no

Examples:
  # Show metrics for all nodes
  kubectl top node

  # Show metrics for a given node
  kubectl top node NODE_NAME

Options:
      --heapster-namespace='kube-system': Namespace Heapster service is located in
      --heapster-port='': Port name in service to use
      --heapster-scheme='http': Scheme (http or https) to connect to Heapster as
      --heapster-service='heapster': Name of Heapster service
  -l, --selector='': Selector (label query) to filter on, supports '=', '==', and '!='.(e.g. -l
key1=value1,key2=value2)

Usage:
  kubectl top node [NAME | -l label] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

注意:我使用的是 1.10 ,可能在你的版本中,选项不同


推荐阅读