kubernetes 服务器出错(服务不可用):服务器当前无法处理请求(获取nodes.metrics.k8s.io)

cwxwcias  于 2023-05-06  发布在  Kubernetes
关注(0)|答案(2)|浏览(107)

运行'kubectl top nodes'时出现错误:
服务器出错(服务不可用):服务器当前无法处理请求(获取nodes.metrics.k8s.io)

k8s version:
kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:31:33Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}

[root@manager ~]# kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
apps/v1
apps/v1beta1
apps/v1beta2
authentication.k8s.io/v1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1
authorization.k8s.io/v1beta1
autoscaling/v1
autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1beta1
events.k8s.io/v1beta1
extensions/v1beta1
metrics.k8s.io/v1beta1
networking.k8s.io/v1
policy/v1beta1
rbac.authorization.k8s.io/v1
rbac.authorization.k8s.io/v1beta1
scheduling.k8s.io/v1beta1
storage.k8s.io/v1
storage.k8s.io/v1beta1
v1

[root@manager ~]# kubectl get po --all-namespaces

NAMESPACE     NAME                                    READY   STATUS    RESTARTS   AGE
kube-system   coredns-86c58d9df4-km7jc                1/1     Running   0          2d21h
kube-system   coredns-86c58d9df4-vltm9                1/1     Running   0          2d21h
kube-system   etcd-manager                            1/1     Running   0          2d23h
kube-system   kube-apiserver-manager                  1/1     Running   0          5h47m
kube-system   kube-controller-manager-manager         1/1     Running   1          2d23h
kube-system   kube-flannel-ds-amd64-5g8w8             1/1     Running   0          2d23h
kube-system   kube-flannel-ds-amd64-69lcm             1/1     Running   0          2d23h
kube-system   kube-flannel-ds-amd64-9hx2f             1/1     Running   0          2d23h
kube-system   kube-proxy-9s6zm                        1/1     Running   0          2d23h
kube-system   kube-proxy-k4qwz                        1/1     Running   0          2d23h
kube-system   kube-proxy-wnzgd                        1/1     Running   0          2d23h
kube-system   kube-scheduler-manager                  1/1     Running   1          2d23h
kube-system   kubernetes-dashboard-79ff88449c-7fpw6   1/1     Running   0          2d23h
kube-system   metrics-server-68d85f76bb-pj8bs         1/1     Running   0          111m
kube-system   tiller-deploy-5478b6c547-bf82v          1/1     Running   0          4h7m

[root@manager ~]# kubectl logs -f -n kube-system metrics-server-68d85f76bb-pj8bs

I1217 06:42:43.451782       1 serving.go:273] Generated self-signed cert (apiserver.local.config/certificates/apiserver.crt, apiserver.local.config/certificates/apiserver.key)
[restful] 2018/12/17 06:42:44 log.go:33: [restful/swagger] listing is available at https://:443/swaggerapi
[restful] 2018/12/17 06:42:44 log.go:33: [restful/swagger] https://:443/swaggerui/ is mapped to folder /swagger-ui/
I1217 06:42:44.099720       1 serve.go:96] Serving securely on [::]:443

并且没有系统错误日志。如何解决此问题?
操作系统:CentOS Linux release 7.5.1804(Core)

h79rfbju

h79rfbju1#

我已经解决了这个问题,将hostNetwork: true添加到metries-server.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: metrics-server
  name: metrics-server
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: metrics-server
  strategy:
    rollingUpdate:
      maxUnavailable: 0
  template:
    metadata:
      labels:
        k8s-app: metrics-server
    spec:
      hostNetwork: true ## add

文档:

[root@xx yaml]# kubectl explain deployment.spec.template.spec.hostNetwork
KIND:     Deployment
VERSION:  apps/v1

FIELD:    hostNetwork <boolean>

DESCRIPTION:
     Host networking requested for this pod. Use the host's network namespace.
     If this option is set, the ports that will be used must be specified.
     Default to false.

背景:
成功运行度量,但发生了kubectl top nodesError from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)

rur96b6h

rur96b6h2#

此问题已解决:
1.删除代理(file:/etc/kubernetes/manifests/kube-apiserver.yaml
1.重启kubelet服务
kubectl top nodes现在应该可以工作了

相关问题