Accessing Kubernetes Using the Web UI (Kubernetes Dashboard)
Step 1: Deploy the Kubernetes Dashboard
To install the Kubernetes Dashboard, apply the recommended deployment YAML:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
This command creates the necessary namespaces, services, deployments, and RBAC roles.
Verify that the dashboard is running:
kubectl get pods -n kubernetes-dashboard
Expected output:
kubernetes-dashboard-xxxxxxxxxx-xxxxx Running 1/1 10s
Step 2: Create an Admin User
To access the dashboard, you need proper authentication. Create an admin user with full access rights.
Create a service account file (admin-user.yaml):
apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard
Create a ClusterRoleBinding file (admin-role.yaml):
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard
Apply the files:
kubectl apply -f admin-user.yaml
kubectl apply -f admin-role.yaml
Step 3: Retrieve the Login Token
Once the service account is created, generate an authentication token:
kubectl -n kubernetes-dashboard create token admin-user
Copy the output token; you’ll need it to log in.
Step 4: Access the Kubernetes Dashboard
To access the dashboard, forward the service to a local port:
kubectl port-forward -n kubernetes-dashboard service/kubernetes-dashboard 10443:443
This will forward the Kubernetes Dashboard service to your local machine on port 10443.
Now, open your browser and navigate to:
Since the dashboard uses a self-signed certificate, your browser might show a security warning. Click Advanced → Proceed to localhost to continue.
Step 5: Login to the Dashboard
On the login page, select the Token authentication method and paste the token you copied earlier. Click Sign In.
Once logged in, you can now visualize your cluster's workloads, view logs, and manage resources using the Kubernetes Dashboard.
Note: Post working with dashboard if you wanna delete it follow below commads.
kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
Additionally, remove the admin user resources:
kubectl delete serviceaccount admin-user -n kubernetes-dashboard
kubectl delete clusterrolebinding admin-user
Check if any Dashboard-related resources remain:
kubectl get all -n kubernetes-dashboard
If the namespace still exists, delete it manually:
kubectl delete namespace kubernetes-dashboard
This will completely remove all Dashboard-related components from your cluster.
Join the conversation