已应用Kubernetes Dashboard YAML却无服务/部署,如何用公网IP暴露服务?
It sounds like you’ve hit a common snag when setting up the Kubernetes Dashboard—let’s break down the likely issues and how to fix them:
1. Verify the YAML was actually applied successfully
First things first: did the kubectl apply command complete without errors? It’s easy to miss a typo in the command or YAML path that causes resource creation to fail.
Re-run the apply command and check the output closely:
sudo kubectl apply -f <your-dashboard-yaml-file>You should see confirmation messages like
deployment.apps/kubernetes-dashboard createdorservice/kubernetes-dashboard created. If you get syntax errors, permission warnings, or path not found messages, that’s your first fix.Check recent cluster events for hidden failures:
sudo kubectl get events --sort-by='.metadata.creationTimestamp'This will show if there were issues pulling the Dashboard image, scheduling pods, or creating services that didn’t show up in the apply command output.
2. Check the correct namespace
The official Kubernetes Dashboard is deployed to the kube-system namespace by default—but when you run kubectl get services or kubectl get deployment without specifying a namespace, it only checks the default namespace.
- List all resources in the
kube-systemnamespace to confirm Dashboard exists:
If you see deployment, service, and pod entries here, that means the resources are live—you just weren’t looking in the right place!sudo kubectl get all -n kube-system | grep dashboard
3. Validate your Dashboard YAML file
If the apply command succeeded but resources still don’t show up, double-check your YAML content:
- Ensure the
apiVersionvalues match your Kubernetes cluster version (e.g.,apps/v1for deployments is required in K8s 1.19+). - Confirm the
kindfields are correctly set toDeploymentandServicefor the core Dashboard resources. - If you modified the YAML to use a custom namespace, make sure the
metadata.namespacefield is set properly, and adjust yourkubectlcommands to target that namespace.
4. Check cluster and kubectl context health
- Make sure all your cluster nodes are in a healthy state:
Any nodes markedsudo kubectl get nodesNotReadycould prevent Dashboard pods from being scheduled. - Verify you’re connected to the correct cluster:
If you have multiple clusters configured, it’s possible you applied the YAML to a different cluster than the one you’re checking.sudo kubectl config current-context
Once you locate the missing resources, you can proceed with exposing the service using a NodePort or LoadBalancer type (depending on your cluster setup) to access it via your server’s public IP.
内容的提问来源于stack exchange,提问作者Warok

