kubernetes远程访问仪表板

时间:2019-11-24 18:24:35

标签: kubernetes

在开始之前,我只有一个关于kubernetes的问题,通常linux服务器没有图形界面,因此管理员如何访问k8S仪表板?

是否还有其他解决方案需要ssh隧道?

我尝试过ssh隧道,但无法正常工作

我已执行的主命令:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta1/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard unchanged
serviceaccount/kubernetes-dashboard unchanged
service/kubernetes-dashboard unchanged
secret/kubernetes-dashboard-certs unchanged
secret/kubernetes-dashboard-csrf unchanged
secret/kubernetes-dashboard-key-holder unchanged
configmap/kubernetes-dashboard-settings unchanged
role.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard unchanged
deployment.apps/kubernetes-dashboard configured
service/dashboard-metrics-scraper configured
deployment.apps/kubernetes-metrics-scraper created
[rbo@K8SMaster ~]$ kubectl proxy
Starting to serve on 127.0.0.1:8001

在远程计算机上完成隧道SSH:

Authenticated to k8smaster ([192.168.1.15]:22).
debug1: Local connections to LOCALHOST:8080 forwarded to remote address localhost:8001
debug1: Local forwarding listening on ::1 port 8080.
debug2: fd 5 setting O_NONBLOCK
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 8080.
debug2: fd 6 setting O_NONBLOCK
debug1: channel 1: new [port listener]
debug2: fd 3 setting TCP_NODELAY
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.

来自远程计算机的浏览器消息:

  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "services \"kubernetes-dashboard\" not found",
  "reason": "NotFound",
  "details": {
    "name": "kubernetes-dashboard",
    "kind": "services"
  },
  "code": 404
}

2 个答案:

答案 0 :(得分:0)

很久以前,我曾用is-accessing-kubernetes-dashboard-remotely-possible文章来解决同样的问题。 SSH隧道也采用这种方法

1)部署仪表板(您可以从original source中获取它)

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yam

2)kubectl proxy&

3)创建serviceaccount,授予它cluster-admin角色

kubectl create serviceaccount rab
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=default:rab
kubectl get secret
kubectl describe secret rab-token-***** (and retrieve token from output. You will need it to access dashboard in the future steps)

4)从要访问仪表板的群集外部的远程主机创建ssh隧道:

ssh -L 9999:127.0.0.1:8001 -N -f -l rab <k8s master host name or ip>

“-L”本地端口转发

“ 9999”是本地主机端口。它可以是任何可用的端口。也可以是8001 代理在k8s主控主机上运行的位置为“ 127.0.0.1:8001”

主主机上的可能需要密码才能创建隧道 此命令将端口9999上的任何本地请求转发到主控主机上的“ 127.0.0.1:8001”

5)使用以下api打开浏览器:

http://localhost:9999/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

然后选择“令牌”并越过令牌以登录仪表板。

希望它对您有帮助

答案 1 :(得分:0)

我做了一个UI工具来帮助您将任何服务转发到本地计算机。

您可以看到有关如何转发仪表板的示例:

Tunnel dashboard

以下是有关如何入门的存储库链接:linker-tool

如果您有任何问题,请打开一个问题或与我联系,我们很乐意为您提供帮助。