Kubernetes
Kubernetes Dashboard
Sign In
Access Guide
Kubernetes Management

How to sign in kubernetes dashboard?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Kubernetes Dashboard is a web-based user interface that allows you to manage, deploy, monitor, and troubleshoot applications on your Kubernetes clusters in a visual and intuitive manner. Signing into the Kubernetes Dashboard requires specific steps and understanding of the access control mechanism within Kubernetes. This article provides a technical guide on how to sign into the Kubernetes Dashboard, including setting up necessary components and credentials.

Prerequisites

Before signing in to the Kubernetes Dashboard, ensure you have the following:

  • A running Kubernetes cluster.
  • Kubernetes command-line tool (kubectl) configured to communicate with your cluster.
  • Access to the cluster with sufficient permissions.
  • Helm (optional, for easy installation of the dashboard).

Step-by-Step Guide to Signing in

1. Deploy the Kubernetes Dashboard

To access the Kubernetes Dashboard, it must be deployed to your cluster. You can do this using kubectl with the following command:

bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml

This command applies the recommended configuration which sets up the dashboard with necessary resources.

2. Accessing the Dashboard

The Kubernetes Dashboard is typically exposed via a proxy connection:

bash
kubectl proxy

This command sets up a local proxy that you can access from http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.

3. Creating a Service Account and Cluster Role Binding

The Dashboard needs authentication to allow access. You can create a service account and cluster role binding as follows:

bash
1# Create a service account
2kubectl create serviceaccount dashboard-admin-sa -n default
3
4# Create a cluster role binding for the service account
5kubectl create clusterrolebinding dashboard-admin-sa --clusterrole=cluster-admin --serviceaccount=default:dashboard-admin-sa

4. Retrieve the Bearer Token

Retrieve the token that will be used for signing in:

bash
kubectl get secret $(kubectl get serviceaccount dashboard-admin-sa -n default -o jsonpath="{.secrets[0].name}") -n default -o jsonpath="{.data.token}" | base64 --decode

This command fetches the token, decodes it, and displays it. Copy this token as it will be used to authenticate to the Dashboard.

5. Sign In

Open the Kubernetes Dashboard URL in your browser and select "Token" as the sign-in method. Paste the copied token into the form and click "Sign in." You should now have access to the Dashboard.

Additional Details

Setting Up RBAC for Restricted Access

To minimize risk, it is recommended to configure Role-Based Access Control (RBAC) with the minimum required privileges.

Create a custom role and role binding:

bash
1# Define a Role with limited permissions
2kubectl apply -f - <<EOF
3apiVersion: rbac.authorization.k8s.io/v1
4kind: Role
5metadata:
6  namespace: default
7  name: limited-access
8rules:
9- apiGroups: [""]
10  resources: ["pods", "services", "deployments"]
11  verbs: ["get", "list"]
12EOF
13
14# Bind the Role to the service account
15kubectl create rolebinding limited-access-binding --role=limited-access --serviceaccount=default:dashboard-admin-sa -n default

This setup grants the service account only the necessary privileges to view pods, services, and deployments.

Troubleshooting

  • 403 Forbidden Error: Ensure that the token has the necessary privileges, and re-check the RBAC settings.
  • Dashboard Not Accessible: Confirm kubectl proxy is running and the local machine has network access to the cluster.
  • Token Missing: Verify that the service account was correctly created and linked to the cluster role binding.

Key Points Summary

StepDescription
Deploy DashboardUse kubectl apply to deploy the Dashboard to the cluster.
Set Up ProxyRun kubectl proxy for local access.
Create Service AccountUse kubectl create serviceaccount for authentication purposes.
Cluster Role BindingBind the service account to necessary roles using kubectl create clusterrolebinding.
Retrieve TokenAcquire the token using kubectl commands for signing in.
RBAC ConfigurationOptionally, configure RBAC for more secure, restricted access.

Conclusion

Signing into the Kubernetes Dashboard involves setting up the Dashboard in your cluster, configuring service accounts with appropriate permissions, and securely retrieving and using a bearer token for authentication. By following this guide, you can ensure proper access to your cluster’s UI interface while maintaining necessary security protocols.


Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.