0

关于这个主题有很多问题,我尝试了很多东西,但仍然没有用。

我是 Kubernetes 新手。我有一个 Kubernetes 集群,有 2 个节点(1 台 PC,另一台 PC 上的 1 个 VM)、1 个主节点、1 个节点。我启动了一个网站(Docker Image)并且 Pod 在节点(不是主节点)上运行。现在我想自动缩放 Pod,这就是我所做的:

  1. 设置--request='cpu=50m'到吊舱
  2. 创建 hpa:kubectl autoscale deployment testwebsite --min=1 --max=4 --cpu-percent=25
  3. 用过的:kubectl get hpa -w

现在存在输出显示为当前值的问题。我读了很多我必须将请求分配给 pod,就像我一样。通过以下方式检查:kubectl get pod testwebsite --out=yaml

我还创建了度量服务器版本 1.8+。确保它通过以下方式运行:kubectl get pods --all-namespaces

之后,我尝试调试 HPA 并通过以下方式对其进行了研究:

kubectl describe hpa testwebsite

这向我展示了这一点:

Name:                                                  testwebsite
Namespace:                                             default
Labels:                                                <none>
Annotations:                                           <none>
CreationTimestamp:                                     Thu, 04 Apr 2019 14:08:57 +0200
Reference:                                             Deployment/testwebsite
Metrics:                                               ( current / target )   resource cpu on pods  (as a percentage of request):  <unknown> / 25%
Min replicas:                                          1
Max replicas:                                          4
Deployment pods:                                       1 current / 0 desired
Conditions:
  Type           Status  Reason                   Message
  ----           ------  ------                   -------
 AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
 ScalingActive  False   FailedGetResourceMetric  the HPA was unable to compute the replica count: unable to get metrics for resource cpu: no metrics returned from resource metrics API
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedComputeMetricsReplicas  7m24s (x12 over 10m)  horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
  Warning  FailedGetResourceMetric       5s (x41 over 10m)     horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

10 多分钟后,它不会显示当前值,即使 CPU 使用率为 50-100%,它也不会按比例放大。

正如我所说,我是 Kubernetes 新手,我真的希望有人能帮助我。

此致,

Nico 又名 Myridor

编辑:在两个节点上使用 Ubuntu 18.04 LTS | Kubernetes 版本:1.14.0

4

2 回答 2

0

您确定 kubernetes 指标服务器和指标 api 正在运行吗?这首先是必要的,它用于检查 CPU 使用情况和限制

您可以从部署中删除限制(如果有)并尝试。

于 2019-04-05T04:13:34.860 回答
0

问题不在于 HPS 本身,而在于无法抓取指标的指标服务器。

我通过克隆metrics-server git然后通过kubectl create -f deploy/1.8+/.

接下来,我通过运行以下命令编辑了指标服务器部署:kubectl edit deployment metrics-server -n kube-system

spec:->containers:添加以下标志:

spec:
      containers:
      - command:
        - /metrics-server
        - --kubelet-insecure-tls

git中所述:

--kubelet-insecure-tls:跳过验证 Kubelet CA 证书。不推荐用于生产环境,但在具有自签名 Kubelet 服务证书的测试集群中很有用。

在更新部署并且指标服务器抓取指标后,您应该会看到 HPA 已更新为当前目标。默认抓取间隔为 60 秒,您可以通过将以下标志添加到上述--metric-resolution=10s<- 间隔设置为 10 秒来更改它。

于 2019-04-05T14:14:37.133 回答