为什么 Openshift 无法访问指标 API 但指标已设置?

为什么 Openshift 无法访问指标 API 但指标已设置?

我正在尝试让自动缩放在 openshift OKD 上工作。我正在使用 Openshift 3.11。

因此,我安装了指标和 Hawkular 指标,并设置了 url 以及主机文件以指向它。

获取HorizontalPodAutoscaler

oc describe hpa

给出:

Name:                                                  blog
Namespace:                                             demo
Labels:                                                <none>
Annotations:                                           <none>
CreationTimestamp:                                     Mon, 28 Oct 2019 13:35:07 +0200
Reference:                                             DeploymentConfig/blog
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  <unknown> / 50%
Min replicas:                                          1
Max replicas:                                          10
DeploymentConfig pods:                                 3 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: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)
Events:
  Type     Reason                        Age                From                       Message
  ----     ------                        ----               ----                       -------
  Warning  FailedComputeMetricsReplicas  1h (x41 over 1h)   horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)
  Warning  FailedGetResourceMetric       4m (x171 over 1h)  horizontal-pod-autoscaler  unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)

因此它无法访问 Metrics API。

此外,获取 metricsAPIProxy 还可以提供:

oc adm diagnostics MetricsApiProxy

给出:

[Note] Determining if client configuration exists for client/cluster diagnostics
Info:  Successfully read a client config file at '/Users/example/.kube/config'
Info:  Using context for cluster-admin access: 'demo/openshift-example-co-za:8443/exampleh'

[Note] Running diagnostic: MetricsApiProxy
       Description: Check the integrated heapster metrics can be reached via the API proxy

ERROR: [DClu4003 from diagnostic MetricsApiProxy@openshift/origin/pkg/oc/cli/admin/diagnostics/diagnostics/cluster/metrics.go:89]
       Unable to access the metrics API Proxy endpoint /api/v1/proxy/namespaces/openshift-infra/services/https:heapster:/api/v1/model/metrics:
       (*errors.StatusError) the server could not find the requested resource
       The Horizontal Pod Autoscaler is not able to retrieve metrics to drive scaling.

[Note] Summary of diagnostics execution (version v3.11.0+0cbc58b):
[Note] Errors seen: 1

答案1

https://docs.openshift.com/container-platform/3.11/dev_guide/pod_autoscaling.html#req-for-using-hpas

要使用水平 pod 自动扩缩器,您需要安装 OpenShift Container Platform 指标服务器:

$ ansible-playbook \ /usr/share/ansible/openshift-ansible/playbooks/metrics-server/config.yml \ -e openshift_metrics_server_install=true

您可以通过运行以下命令来验证服务器是否已正确安装:

$ oc adm 顶部节点 $ oc adm 顶部 pod

相关内容