首页 > 解决方案 > 如何让 kubernetes 仪表板的 kubectl 代理正常工作?

问题描述

我在运行 ubuntu server 20.04 的三台服务器上设置了一个高可用的 microk8s 集群。我启用了仪表板插件并尝试使用命令转发它

kubectl port-forward -n kube-system service/kubernetes-dashboard 10443:443

在 WSL Ubuntu 中,在 kubeconfig 文件中配置了 microk8s 集群,但它返回了错误

error: error upgrading connection: error dialing backend: dial tcp 192.168.250.235:10250: connect: no route to host

所以然后我尝试microk8s dashboard-proxy在其中一台服务器上运行以查看是否可行,它返回了错误

Checking if Dashboard is running.
Dashboard will be available at https://127.0.0.1:10443
Use the following token to login:
<TOKEN>
error: error upgrading connection: error dialing backend: dial tcp 192.168.250.235:10250: connect: no route to host
Traceback (most recent call last):
  File "/snap/microk8s/1710/scripts/wrappers/dashboard-proxy.py", line 80, in <module>
    dashboard_proxy()
  File "/snap/microk8s/1710/scripts/wrappers/dashboard-proxy.py", line 74, in dashboard_proxy
    check_output(command)
  File "/snap/microk8s/1710/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/snap/microk8s/1710/usr/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['/snap/microk8s/current/microk8s-kubectl.wrapper', 'port-forward', '-n', 'kube-system', 'service/kubernetes-dashboard', '10443:443', '--address', '0.0.0.0']' returned non-zero exit status 1

在 microk8s 集群中启用了插件仪表板、dns、ha-cluster、helm3 和 metrics-server。

kubectl get nodes返回以下输出:

NAME    STATUS   ROLES    AGE    VERSION
esx02   Ready    <none>   93m    v1.19.2-34+1b3fa60b402c1c
esx03   Ready    <none>   87m    v1.19.2-34+1b3fa60b402c1c
esx01   Ready    <none>   101m   v1.19.2-34+1b3fa60b402c1c

esx01 的 IP 为 192.168.250.51,esx02 的 IP 为 192.168.250.52,esx03 的 IP 为 192.168.250.53。

的输出kubectl -n kube-system describe service/kubernetes-dashboard是:

Name:              kubernetes-dashboard
Namespace:         kube-system
Labels:            k8s-app=kubernetes-dashboard
Annotations:       <none>
Selector:          k8s-app=kubernetes-dashboard
Type:              ClusterIP
IP:                10.152.183.174
Port:              <unset>  443/TCP
TargetPort:        8443/TCP
Endpoints:         10.1.40.194:8443
Session Affinity:  None
Events:            <none>

标签: kubernetesmicrok8s

解决方案


推荐阅读