ubuntu - 如何从外部访问规范的 kubernetes 仪表板?

标签 ubuntu kubernetes kubectl

如何从外部网络/IP 访问规范的 kubernetes 仪表板?
有没有办法在外部公开仪表板服务,而不是从规范 k8s 集群节点所在的本地主机浏览器访问?

最佳答案

The documentation has a guide关于如何去做。
使用 kubectl 代理kubectl proxy在您的机器和 Kubernetes API 服务器之间创建代理服务器。默认情况下,它只能在本地访问(从启动它的机器)。
启动本地代理服务器:

$ kubectl proxy

Starting to serve on 127.0.0.1:8001
代理服务器启动后,您应该能够从浏览器访问 Dashboard。
要访问仪表板的 HTTPS 端点,请访问:http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/注意:仪表板不应使用 kubectl proxy 命令公开公开,因为它只允许 HTTP 连接。对于 localhost 和 127.0.0.1 以外的域,将无法登录。单击登录页面上的登录按钮后不会发生任何事情。
使用节点端口
这种访问 Dashboard 的方式仅推荐用于单节点设置中的开发环境。
编辑 kubernetes-dashboard服务。
$ kubectl -n kube-system edit service kubernetes-dashboard
您应该会看到服务的 yaml 表示。将类型:ClusterIP 更改为类型:NodePort 并保存文件。如果已经更改,请转到下一步。
# 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
status:
  loadBalancer: {}
接下来我们需要检查 Dashboard 暴露的端口。
$ kubectl -n kube-system get service kubernetes-dashboard
NAME                   CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes-dashboard   10.100.124.90   <nodes>       443:31707/TCP   21h
仪表板已在端口 31707 (HTTPS) 上公开。现在您可以通过浏览器访问它:https://<master-ip>:31707 . master-ip可以通过执行kubectl cluster-info找到.通常它是您机器的 127.0.0.1 或 IP,假设您的集群直接在执行这些命令的机器上运行。
如果您尝试在多节点集群上使用 NodePort 公开 Dashboard,那么您必须找出运行 Dashboard 的节点的 IP 才能访问它。而不是访问 https://<master-ip>:<nodePort>您应该访问 https://<node-ip>:<nodePort> .
API 服务器
如果 Kubernetes API 服务器暴露并从外部访问,您可以直接访问仪表板:https://<master-ip>:<apiserver-port>/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/入口
仪表板也可以使用 Ingress 资源公开。例如
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: kubernetes-dashboard-ingress
 namespace: kube-system
spec:
 rules:
   — host: kubernetes
     http:
       paths:
         — path: /ui
           backend:
             serviceName: kubernetes-dashboard
             servicePort: 80

关于ubuntu - 如何从外部访问规范的 kubernetes 仪表板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48286170/

相关文章:

linux - 文本 block 内的 tesseract 整数识别

Jenkins 管道 : kubectl: not found

amazon-web-services - Kube-up.sh在特定的AWS区域中永远循环

kubernetes - 错误 : forwarding ports: error upgrading connection: Upgrade request required

kubernetes - kubectl status.phase=运行返回错误结果

mongodb - 将 kubectl exec 的返回值获取到 powershell 脚本中

c - 如何通过cronjob调度定期调用C程序中的特定函数?

ubuntu - 在 Nginx : 上运行 Siremis web

linux - 创建共享对象时,不能使用针对符号 _ZTISt13runtime_error@@GLIBCXX_3.4 的重定位 R_X86_64_PC32;使用 -fPIC 重新编译

kubernetes - 如何获得K8s集群中的可用资源(内存,CPU)?