如何从外部访问Play with Kubernetes中的Kubernetes Dashboard?
Hey there, let's break down why you're having trouble accessing the Kubernetes Dashboard in your Play with Kubernetes environment—this is a common gotcha with the default Dashboard setup!
The Core Issue
By default, the Kubernetes Dashboard Service is created as a ClusterIP type (as you saw in your output: TYPE ClusterIP). ClusterIPs are only accessible inside the Kubernetes cluster, so they can't be reached directly from the Play with Kubernetes UI or your local browser. Play with Kubernetes relies on exposing services via NodePorts to make them externally accessible.
Step-by-Step Fix
Here’s exactly what you need to do to get the Dashboard working:
Change the Dashboard Service type to NodePort
Run this command to patch the existing Service and switch it to NodePort mode:kubectl patch service kubernetes-dashboard -n kube-system -p '{"spec":{"type":"NodePort"}}'Get the assigned NodePort
Fetch the updated Service details to find the public port that was automatically assigned:kubectl get service kubernetes-dashboard -n kube-systemYou’ll see output like this (note the
PORT(S)column—this example uses30007as the NodePort):NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard NodePort 10.98.185.58 <none> 443:30007/TCP 1hAccess the Dashboard via Play with Kubernetes UI
- Look at the top-right corner of your master node (or the node where the Dashboard Pod is running—you can confirm with
kubectl get pods -n kube-system -o wide | grep kubernetes-dashboardif unsure) - Click the Port button, enter the NodePort number you found (e.g.,
30007), and hit enter - Your browser will open a new tab to the Dashboard. You’ll see a certificate warning (since it uses a self-signed cert)—just proceed past the warning to access the login screen.
- Look at the top-right corner of your master node (or the node where the Dashboard Pod is running—you can confirm with
Quick Checks to Rule Out Other Issues
- Make sure the Dashboard Pod is running:
If it’s not inkubectl get pods -n kube-system | grep kubernetes-dashboardRunningstate, wait a minute for it to start, or check logs withkubectl logs <pod-name> -n kube-systemfor errors. - Double-check that you’re using the correct NodePort—don’t try to use the 443 port directly (that’s the internal ClusterIP port).
This should resolve your access issue! The key was switching the Service type from ClusterIP to NodePort, which lets Play with Kubernetes expose the service to the outside world.
内容的提问来源于stack exchange,提问作者Mark Estrada

