从远程客户端访问kubernetes Web UI

时间:2019-01-07 20:46:47

标签: kubernetes kubernetes-dashboard

我在Ubuntu服务器上运行了一个集群。我通过端口80/443在群集中运行的服务器上提供Web内容。我只能通过ssh访问服务器本身,因此根本没有图形界面。

现在,我要访问该集群的kubernetes web ui。在研究期间,我发现有消息人士说,不建议在产品环境中使用每个远程访问来访问web ui。这些指南仅涉及使用kubectl proxy将仪表板公开给localhost。

是否有解决方案或某种或多或少的通用方法来访问服务器上运行的集群的仪表板?

5 个答案:

答案 0 :(得分:0)

kubectl proxy效果很好。否则,您也可以将kubernetes-dashboard更改为负载均衡器/节点端口,并通过该端口访问群集。

如果您使用的是负载均衡器,并且使用的是AWS或Azure之类的云提供商,则可以设置安全组以允许在某些特定ip范围内进行访问。

但是,我会说kubectl proxy在大多数情况下都足够好。

答案 1 :(得分:0)

如果您要通过外部IP地址访问仪表板,则可以编辑仪表板服务,如果您具有外部LB提供程序(例如GCP或AWS),则可以将类型更改为LoadBalancer。 为此,请执行Edit kubernetes-dashboard服务。

# kubectl -n kube-system edit service kubernetes-dashboard

您应该看到该服务的yaml表示形式。更改类型: ClusterIP 以键入: LoadBalancer 并保存文件。如果已经更改,请转到下一步。

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
...
  name: kubernetes-dashboard
  namespace: kube-system
  resourceVersion: "343478"
  selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard-head
  uid: 8e48f478-993d-11e7-87e0-901b0e532516
spec:
  clusterIP: 10.100.124.90
  externalTrafficPolicy: Cluster
  ports:
  - port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: ClusterIP # <-- Change to LoadBalancer
status:
  loadBalancer: {}

然后运行以下命令以查看Kubernetes Dashboard服务的外部IP地址

# kubectl -n kube-system get service kubernetes-dashboard
NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)         AGE
kubernetes-dashboard   LoadBalancer   10.23.252.164   <external-ip>   443:31720/TCP   26d

然后浏览https://<external-ip>来查看Web UI

您还可以将服务公开为NodePort,以通过子网访问WEB UI

答案 2 :(得分:0)

2件事; 1.要使用浏览器(本地计算机)直接访问,k8s群集必须位于同一网络域中。 2.如果您不在项目#1上,请使用Windows RDP并使用浏览器进行访问。

答案 3 :(得分:0)

...
spec:
  clusterIP: 10.104.126.244
  externalIPs:
  - 192.168.64.1
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 31180
    port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: LoadBalancer
status:

上述kubernetes-dashboard-service将可以运行,方法是转到https://192.168.64.1:31180, 其中192.168.64.1是您的Kubernetes Controller的IP地址, 但是有一些警告。

您需要使用旧的浏览器来访问它并接受安全例外。

然后运行

kubectl -n kube-system get secret

然后查找您的replicaset-controller-token-kzpmc

然后运行

$ kubectl -n kube-system describe secrets replicaset-controller-token-kzpmc

然后在底部复制长令牌。

Name:       replicaset-controller-token-kzpmc
Namespace:  kube-system
Labels:     <none>
Annotations:    kubernetes.io/service-account.name=replicaset-controller
        kubernetes.io/service-account.uid=d0d93741-96c5-11e7-8245-901b0e532516

Type:   kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3 

答案 4 :(得分:0)

假设 K8s 控制面板已部署在您的集群上,通过运行以下命令将所有请求从您的 Amazon EC2 实例本地主机端口转发到 Kubernetes 控制面板端口:

kubectl port-forward svc/kubernetes-dashboard -n kubernetes-dashboard 6443:443

然后,要使用 SSH 隧道从本地计算机访问端口,请运行以下命令:

ssh -i <EC2KeyPair.pem> ec2-user@<IP> -L 6443:127.0.0.1:6443

如果您从 AWS EC2 访问,请提供您的 PEM 文件名和 IP。例如,ssh -i "demo.pem" ec2-user@ec2-34-207-214-53.compute-1.amazonaws.com -L 6443:127.0.0.1:6443

此后,从您的 EC2 实例中 exit 并运行:

ssh -i "demo.pem" ec2-user@ec2-34-207-214-53.compute-1.amazonaws.com -L 6443:127.0.0.1:6443

现在可以在浏览器窗口中打开 https://127.0.0.1:6443 以访问 k8s 仪表板

enter image description here 有关详细信息,请参阅https://aws.amazon.com/premiumsupport/knowledge-center/eks-cluster-kubernetes-dashboard/

相关问题