通过Kuboard安装Metrics server

出现的问题可以参考官网:https://kuboard.cn/install/faq/metrics-server.html

但是官网并没有给出明确的解决办法!!!

可以带着疑问继续往下排查!!

当 metrcis-server 出现异常时,相关依赖组件都会受到影响,例如:

执行 kubectl top nodes 指令失败

Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)

在这里插入图片描述

确认 metrics-server 是否正常运行

发现是正常运行的,日志打印为

I0515 08:08:43.918797 1 serving.go:312] Generated self-signed cert (/tm

p/apiserver.crt, /tmp/apiserver.key) I0515 08:08:44.589845 1
secure_serving.go:116] Serving securely on [::]:4443

确认 ApiService 是否正常

status:
  conditions:
    - lastTransitionTime: '2021-05-14T03:32:10Z'
      message: >-
        failing or missing response from
        https://10.104.148.145:443/apis/metrics.k8s.io/v1beta1: Get
        "https://10.104.148.145:443/apis/metrics.k8s.io/v1beta1": dial tcp
        10.104.148.145:443: connect: connection refused
      reason: FailedDiscoveryCheck
      status: 'False'
      type: Available

排查步骤1,根据ApiService的日志,查443端口

根据ApiService的日志,发现https://10.104.148.145:443/apis/metrics.k8s.io/v1beta1:访问不了。
通过curl发现的确访问不了

[root@master-01 ~]# curl -ik https://10.104.148.145:443/apis/metrics.k8s.io/v1beta1
curl: (7) Failed connect to 10.104.148.145:443; 拒绝连接

拒绝链接了

排查步骤2,metrics-server pod日志 查4443端口

[root@master-01 ~]# curl https://10.51.13.60:4443 --insecure
{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
  "reason": "Forbidden",
  "details": {
    
  },
  "code": 403
}

居然可以顺利访问。

解决,既然443端口访问不了,那么久访问4443,改造server

metrics-server 的 service


spec:
  clusterIP: 10.104.148.145
  ports:
    - name: zzmtnt
      port: 443
      protocol: TCP
      targetPort: 4443
  selector:
    k8s-app: metrics-server
  sessionAffinity: None
  type: ClusterIP

顺利解决

[root@master-01 ~]# curl -ik https://10.104.148.145:443/apis/metrics.k8s.io/v1beta1
HTTP/1.1 403 Forbidden
Content-Type: application/json
X-Content-Type-Options: nosniff
Date: Sat, 15 May 2021 08:13:14 GMT
Content-Length: 260

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {
    
  },
  "status": "Failure",
  "message": "forbidden: User \"system:anonymous\" cannot get path \"/apis/metrics.k8s.io/v1beta1\"",
  "reason": "Forbidden",
  "details": {
    
  },
  "code": 403
}
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐