如何通过节点端口启用 kubernetes 仪表板?

How to enable kubernetes dashboard via nodeport?

我正在尝试通过节点端口服务启用仪表板。 我有 3 个虚拟机:

申请后:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

可以通过 kube-proxy 访问仪表板。所以我已经将服务变成了 NodePort:

kubectl edit services kubernetes-dashboard -n kube-system

然后我尝试通过 https NodePort 访问仪表板。它失败了。当我尝试访问 192.168.100.31 或 192.168.100.32 时:

https://192.168.100.31:32443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default

浏览器挂起并引发超时错误。 同时,192.168.100.33 的相同 URL 允许我将站点添加到浏览器异常导致自签名证书和...失败。

This site can’t be reached
The webpage at https://192.168.100.33:32443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/overview?namespace=default might be temporarily down or it may have moved permanently to a new web address.
ERR_INVALID_RESPONSE

kubernetes 版本:v1.11.1

更新:

kubectl get svc kubernetes-dashboard -n kube-system --export -o yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kube-system","selfLink":"/api/v1/namespaces/kube-system/services/kubernetes-dashboard"},"spec":{"ports":[{"nodePort":32443,"port":443,"protocol":"TCP","targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"},"sessionAffinity":"None","type":"NodePort"},"status":{"loadBalancer":{}}}
  creationTimestamp: null
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
spec:
  externalTrafficPolicy: Cluster
  ports:
  - port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

kubectl get svc kubernetes-dashboard -n kube-system

NAME                   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
kubernetes-dashboard   NodePort   10.96.174.242   <none>        443:32443/TCP   52m

kubectl describe svc kubernetes-dashboard -n kube-system

Name:                     kubernetes-dashboard
Namespace:                kube-system
Labels:                   k8s-app=kubernetes-dashboard
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernete...
Selector:                 k8s-app=kubernetes-dashboard
Type:                     NodePort
IP:                       10.96.174.242
Port:                     <unset>  443/TCP
TargetPort:               8443/TCP
NodePort:                 <unset>  32443/TCP
Endpoints:                192.0.2.2:8443
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

看起来您在通过 NodePort 服务直接访问 dashboard 服务时使用了 apiserver 类型的请求。

您能否在浏览器中查看以下链接以访问 Kubernetes 仪表板:

https://192.168.100.31:32433/

https://192.168.100.32:32433/

https://192.168.100.33:32433/

您的 Pod 类型是“NodePort”。很好!

找到你的节点ip(Master ip)

例如输入:

ip a

和...

curl -k http://<Node IP>:32443

尽情享受吧!