How to Install Kubernetes Dashboard on Ubuntu 22.04 LTS

Kubernetes has become the go-to solution for container orchestration, allowing developers and DevOps engineers to deploy and manage applications seamlessly in a cloud-native environment. The Kubernetes Dashboard is an intuitive web-based user interface that simplifies the management of pods, services, deployments, and other Kubernetes resources. Installing the Kubernetes Dashboard on Ubuntu 22.04 LTS enhances your ability to visualize and interact with your cluster’s resources. In this guide, we’ll take you through the step-by-step process of installing and configuring the Kubernetes Dashboard on Ubuntu 22.04 LTS.

Prerequisites

Before you start, ensure that you have:

  • Administrative access to your Ubuntu 22.04 LTS server.
  • Docker installed (install it using sudo apt update && sudo apt install docker.io -y if not already installed).
  • kubectl (Kubernetes command-line tool) and Helm installed and configured.
  • A basic understanding of Kubernetes concepts such as pods, services, and deployments.

Technical Implementation

Step 1: Install Docker and kubectl

Ensure Docker and kubectl are installed on your system:

sudo apt update && sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker

Install kubectl:

sudo apt install -y kubectl

Step 2: Install Helm

Helm is a package manager for Kubernetes, which makes it easy to install and manage applications. Run the following command to install Helm:

curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

Verify Helm installation:

helm version

Step 3: Create a Namespace for the Dashboard

Create a dedicated namespace for the Kubernetes Dashboard:

kubectl create namespace kubernetes-dashboard

Step 4: Deploy the Kubernetes Dashboard

Deploy the Kubernetes Dashboard using kubectl apply:

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

This will deploy the Dashboard resources in the kubernetes-dashboard namespace.

Step 5: Create an Admin User and Bind Cluster Role

To access the Dashboard with full administrative privileges, create an admin user:

  1. Create a YAML file named dashboard-admin-user.yaml:
   apiVersion: v1
   kind: ServiceAccount
   metadata:
     name: admin-user
     namespace: kubernetes-dashboard
  1. Create a ClusterRoleBinding for the admin user by creating admin-user-role-binding.yaml:
   apiVersion: rbac.authorization.k8s.io/v1
   kind: ClusterRoleBinding
   metadata:
     name: admin-user-binding
   roleRef:
     apiGroup: rbac.authorization.k8s.io
     kind: ClusterRole
     name: cluster-admin
   subjects:
   - kind: ServiceAccount
     name: admin-user
     namespace: kubernetes-dashboard

Apply these configurations:

kubectl apply -f dashboard-admin-user.yaml
kubectl apply -f admin-user-role-binding.yaml

Step 6: Access the Dashboard

To access the Kubernetes Dashboard, use the following command to create a proxy:

kubectl proxy

This command starts a local proxy server at http://localhost:8001. Open your web browser and navigate to:

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Step 7: Obtain a Bearer Token for Authentication

Get the token to log in:

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

Copy the token and use it to log in to the Kubernetes Dashboard.

Best Practices

  • Secure Access: Limit Dashboard access by configuring Role-Based Access Control (RBAC).
  • Use HTTPS: Deploy an ingress controller or configure your environment to serve the Dashboard over HTTPS.
  • Monitor Activity: Regularly monitor the Dashboard logs and Kubernetes events for unusual activity.
  • Limit Permissions: Avoid using the admin account for daily operations. Instead, create specific users with appropriate roles for routine tasks.

Troubleshooting

  • Dashboard Not Accessible: Ensure the proxy is running and the correct namespace is specified. Verify the service status with kubectl get svc -n kubernetes-dashboard.
  • Token Issues: Confirm that the token is correctly generated and matches the created user.

Conclusion

In this guide, we’ve covered how to install and set up the Kubernetes Dashboard on Ubuntu 22.04 LTS. By following these steps, you’ll have a powerful interface for managing and visualizing your Kubernetes resources, enhancing your operational capabilities. For continued learning, explore integrating the Dashboard with monitoring tools and setting up secure remote access for distributed teams.