Setting Up a Kubernetes Dashboard on a Local Kind Cluster
Setting Up a Kubernetes Dashboard on a Local Kind Cluster
Ever wanted to visualize your Kubernetes cluster but found the command-line a bit tedious? The Kubernetes Dashboard offers a slick, web-based UI to manage your applications, monitor resource usage, and troubleshoot issues. In this blog post, we'll walk you through the process of setting up the Kubernetes Dashboard on a local Kind cluster and accessing it from your browser.
Prerequisites: What You'll Need
Before we start, make sure you have the following installed on your machine:
Docker: Kind uses Docker to run the Kubernetes cluster.
Kind: The
kind
CLI tool for creating and managing your cluster.kubectl: The command-line tool for interacting with your cluster.
Helm: A package manager for Kubernetes, which is the easiest way to install the Dashboard.
If you don't have a Kind cluster running, you can create one with a simple command: kind create cluster
.
Step 1: Install the Kubernetes Dashboard with Helm
Installing the Dashboard with Helm is a breeze. It handles all the necessary components for you.
First, add the Kubernetes Dashboard Helm repository:
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
Next, update your Helm repositories to ensure you have the latest charts:
helm repo update
Now, install the Dashboard into the kubernetes-dashboard
namespace. We'll add the --create-namespace
flag to have Helm handle that for us.
helm install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard
Wait a few moments for the installation to complete. You can check the status by running:
kubectl get pods --namespace kubernetes-dashboard
You should see a pod named kubernetes-dashboard-xxx
in a Running
state.
Step 2: Create a User and Get an Authentication Token
For security, the Dashboard doesn't allow anonymous access. You need to create a ServiceAccount
and a ClusterRoleBinding
to grant it administrative permissions.
First, save the following YAML content to a file named dashboard-adminuser.yaml
.
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
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 this file to your cluster using kubectl
:
kubectl apply -f dashboard-adminuser.yaml
Now, let's get the authentication token for this new user. For Kubernetes versions 1.24 and newer, the easiest way to do this is with the kubectl create token
command.
kubectl create token admin-user -n kubernetes-dashboard
Copy the long string of characters that's output to your terminal. This is the token you'll use to log in.
Step 3: Access the Dashboard
To access the Dashboard from your local machine, we'll use kubectl
to create a secure proxy. This command forwards requests from your local machine to the Kubernetes API server, bypassing any network firewalls or complex configurations.
Open a new terminal window and run the proxy command. Keep this terminal open!
kubectl proxy
You'll see a message confirming the proxy is running, typically on http://127.0.0.1:8001
.
Finally, open your web browser and navigate to the following URL:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
You'll be greeted by the Dashboard login screen. Select the Token option, paste the token you copied earlier, and click Sign In.
Congratulations! You now have a working Kubernetes Dashboard on your local Kind cluster. You can now use this powerful UI to monitor your pods, view logs, and manage your applications directly from your browser.
Comments
Post a Comment