kubernetes HPA - 未经授权已阻止请求成功

问题描述

我正在尝试为我的应用程序部署 HPA,但出现未授权错误

kubectl desribe hpa homekitchen:
Events:
  Type     Reason                   Age                   From                       Message
  ----     ------                   ----                  ----                       -------
  Warning  FailedGetResourceMetric  13s (x488 over 130m)  horizontal-pod-autoscaler  unable to get metrics for resource memory: unable to fetch metrics from resource metrics API: an error on the server ("Internal Server Error: \"/apis/metrics.k8s.io/v1beta1/namespaces/default/pods?labelSelector=app%3Dhomekitchen\": Unauthorized") has prevented the request from succeeding (get pods.metrics.k8s.io)

kubectl 获取 hpa:

NAME          REFERENCE                TARGETS                        MINPODS   MAXPODS   REPLICAS   AGE
homekitchen   Deployment/homekitchen   <unkNown>/75%,<unkNown>/85%   2         3         2          169m

我的 HPA 配置:

---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
Metadata:
  name: homekitchen
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: homekitchen
  minReplicas: 2
  maxReplicas: 4
  behavior:
    scaleUp:
      policies:
        - type: Pods
          value: 1
          periodSeconds: 70
    scaleDown:
      policies:
        - type: Percent
          value: 10
          periodSeconds: 70
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: utilization
          averageutilization: 85
    - type: Resource
      resource:
        name: memory
        target:
          type: utilization
          averageutilization: 75

在部署配置文件中,我添加了以下内容

 resources:
          requests:
            memory: 500Mi
            cpu: 500m
          limits:
            memory: 1500Mi
            cpu: 1500m

我的指标服务器(命名空间 = kube-system)日志显示以下错误

I0717 11:49:36.396129       1 server.go:188] "Failed probe" probe="metric-storage-ready" err="not metrics to serve"
I0717 11:49:46.396613       1 server.go:188] "Failed probe" probe="metric-storage-ready" err="not metrics to serve"
E0717 11:49:49.529809       1 scraper.go:139] "Failed to scrape node" err="GET \"https://**.**.**.**:**/stats/summary?only_cpu_and_memory=true\": bad status code \"403 Forbidden\"" node="gke-******"
E0717 11:49:49.529921       1 scraper.go:139] "Failed to scrape node" err="GET \"https://**.**.**.**:***/stats/summary?only_cpu_and_memory=true\": bad status code \"403 Forbidden\"" node="gke-*****"

指标服务器的 ClusterRole:

Name:         system:metrics-server
Labels:       addonmanager.kubernetes.io/mode=Reconcile
              kubernetes.io/cluster-service=true
Annotations:  <none>
PolicyRule:
  Resources         Non-Resource URLs  Resource Names  Verbs
  ---------         -----------------  --------------  -----
  deployments.apps  []                 []              [get list update watch]
  namespaces        []                 []              [get list watch]
  nodes             []                 []              [get list watch]
  pods              []                 []              [get list watch]
                    [/metrics]         []              [get]

我有限的知识,我无法弄清楚为什么会出现未经授权的错误

请大家帮帮我

提前致谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)