1080*80 ad

Install Kubernetes Dashboard on Ubuntu

How to Install and Access the Kubernetes Dashboard on Ubuntu: A Step-by-Step Guide

Managing a Kubernetes cluster solely through the command line can be a daunting task, especially when you need a quick, high-level overview of your resources. The Kubernetes Dashboard provides a powerful, web-based user interface that allows you to deploy containerized applications, manage cluster resources, and troubleshoot workloads with ease.

This comprehensive guide will walk you through the entire process of installing the Kubernetes Dashboard on an Ubuntu system, creating a secure admin user, and accessing the UI.

Before You Begin: Prerequisites

To ensure a smooth installation, make sure you have the following ready:

  • A fully operational Kubernetes cluster.
  • The kubectl command-line tool installed and configured to communicate with your cluster.
  • sudo or root privileges on your Ubuntu machine.

Step 1: Deploy the Dashboard to Your Cluster

The first step is to deploy the Dashboard components using the official manifest file provided by the Kubernetes project. This file contains all the necessary configurations for the Dashboard’s services, deployments, and roles.

Execute the following command in your terminal:

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

This command downloads the configuration and applies it to your cluster, creating the necessary resources within the kubernetes-dashboard namespace.

To verify that the Dashboard pod is running correctly, you can check the status of pods in that namespace:

kubectl get pods -n kubernetes-dashboard

Wait until the kubernetes-dashboard- pod shows a status of Running.

Step 2: Create a Service Account for Secure Admin Access

By default, the newly deployed Dashboard has minimal access rights for security reasons. To manage your cluster effectively, you need to create a ServiceAccount with administrative privileges. We will then bind this account to the cluster-admin role.

Warning: The cluster-admin role provides full control over your entire cluster. While suitable for administrative or development environments, you should use more granular Role-Based Access Control (RBAC) policies for production environments.

  1. Create a new file named dashboard-adminuser.yaml using your favorite text editor:

    nano dashboard-adminuser.yaml
    
  2. Copy and paste the following YAML configuration into the file. This defines a ServiceAccount named admin-user and a ClusterRoleBinding to grant it cluster-wide admin rights.

    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
    
  3. Save and close the file. Now, apply this configuration to your cluster:

    kubectl apply -f dashboard-adminuser.yaml
    

You will see confirmation that the serviceaccount/admin-user and clusterrolebinding/admin-user have been created.

Step 3: Get the Bearer Token to Log In

To log into the Dashboard, you’ll need an authentication token associated with the admin-user account you just created. This token acts as your password.

Run the following command to retrieve the token. It specifically targets the secret created for the admin-user service account and extracts the token string.

kubectl -n kubernetes-dashboard create token admin-user

The output will be a long string of characters. This is your login token. Copy it and save it in a secure location; you will need it in the final step.

Step 4: Access the Dashboard Using Kubectl Proxy

The most secure and straightforward way to access the Dashboard from your local machine is by using kubectl proxy. This command creates a secure proxy server that tunnels traffic from your local machine directly to your cluster’s network.

Open a new terminal window and run the following command:

kubectl proxy

This will start the proxy server. You must keep this terminal window open for as long as you want to access the Dashboard.

Now, open your web browser and navigate to the following URL:

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

Step 5: Log In to the Kubernetes Dashboard

You will be presented with the Kubernetes Dashboard login page.

  1. Select the Token option.
  2. Paste the long bearer token you copied in Step 3 into the “Enter token” text field.
  3. Click the Sign in button.

Congratulations! You now have full administrative access to your Kubernetes cluster through a user-friendly web interface. You can explore nodes, view running pods, inspect deployments, and manage all your cluster resources visually.

Security and Cleanup

If you ever need to remove the Kubernetes Dashboard and the associated admin user, you can do so by running the following commands:

# Delete the dashboard deployment
kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

# Delete the admin user and role binding
kubectl delete -f dashboard-adminuser.yaml

Source: https://kifarunix.com/install-kubernetes-dashboard-on-ubuntu/

900*80 ad

      1080*80 ad