Logo AppDev24 Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Kubernetes

Kubernetes Dashboard with Docker Desktop

Updated on Aug 15, 2024

Kubernetes has become the go-to orchestration platform for containerized applications, providing robust capabilities to manage large-scale deployments. One essential tool within the Kubernetes ecosystem is the Kubernetes Dashboard, a web-based interface that allows users to manage and monitor their Kubernetes clusters. In this article, we will explore how to set up and use the Kubernetes Dashboard with Docker Desktop.

Docker Desktop

Ensure you have Docker Desktop installed and running on your machine. Docker Desktop includes a single-node standalone Kubernetes cluster that runs locally  within a Docker container on your local machine (non configurable), and is ideal for local application testing.

You can easily enable Kubernetes using the Docker Dashboard settings, under  Kubernetes from the sidebar, Apply & Restart, then Install.

Install Kubectl

kubectl is a command line tool for communicating with a Kubernetes cluster's control plane, using the Kubernetes API.

brew install kubectl
# brew install kubernetes-cli

kubectl version --client

Set Kubeconfig Context

Set the kubeconfig context to docker-desktop.

kubectl config get-contexts
kubectl config use-context docker-desktop

Test Kubernetes Cluster

Let us now test the Kubernetes cluster by listing the available nodes.

kubectl cluster-info

kubectl get nodes

This command should display information about the Kubernetes master and other components, confirming that your cluster is up and running.

Install Helm

Helm is the package manager for Kubernetes.

brew install helm
helm version

Install NGINX Ingress Controller

ingress-nginx is an Ingress controller for Kubernetes using NGINX as a reverse proxy and load balancer. Let us install the nginx ingress controller using Helm.

helm upgrade --install ingress-nginx ingress-nginx \
  --repo https://kubernetes.github.io/ingress-nginx \
  --namespace ingress-nginx --create-namespace

It will install the controller in the ingress-nginx namespace, creating that namespace if it doesn't already exist.

Install Kubernetes Metrics Server

Kubernetes Metrics Server is a cluster-wide aggregator of resource usage data, providing metrics like CPU and memory usage for nodes and pods to facilitate autoscaling and monitoring within a Kubernetes cluster.

Let us install the metrics-server using Helm. We need to also add the --kubelet-insecure-tls argument to disable Kubelet certificate validation.

helm upgrade --install metrics-server metrics-server \
  --repo https://kubernetes-sigs.github.io/metrics-server/ \
  --set 'args[0]=--kubelet-insecure-tls' \
  --namespace kube-system
kubectl -n kube-system get deployment metrics-server -o yaml

Install Kubernetes Dashboard

Kubernetes Dashboard is a general purpose, web-based UI for Kubernetes clusters. It allows users to manage applications running in the cluster and troubleshoot them, as well as manage the cluster itself.

Use the following command to install the Kubernetes Dashboard with nginx ingress enabled:

helm upgrade --install kubernetes-dashboard kubernetes-dashboard \
  --repo https://kubernetes.github.io/dashboard/ \
  --namespace kubernetes-dashboard --create-namespace \
  --set app.ingress.enabled=true \
  --set app.ingress.ingressClassName=nginx \
  --set "app.ingress.hosts[0]=kubernetes-dashboard.local"

Update /etc/hosts file

To access the dashboard using kubernetes-dashboard.local, you need to add an entry to your /etc/hosts file:

Add the following line:

127.0.0.1 kubernetes-dashboard.local

Create Admin User

To access the dashboard, you need to create a service account and bind it with the necessary roles and grant this user admin permissions and login to Kubernetes Dashboard using a bearer token tied to this user.

Create Service Account

Let us first create a Service Account with the name dashboard-admin in the kubernetes-dashboard namespace.

sa.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: dashboard-admin
  namespace: kubernetes-dashboard
kubectl apply -f sa.yaml

Creating a ClusterRoleBinding

Next we will create a ClusterRoleBinding for the ServiceAccount to cluster-admin ClusterRole.

crb.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: dashboard-admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: dashboard-admin
  namespace: kubernetes-dashboard
kubectl apply -f crb.yaml

Create a Bearer Token

Finally we will create a bearer token for the ServiceAccount to login to Kubernetes Dashboard. We will create a long lived token saved in a secret which bound the service account and the token.

secret.yaml

apiVersion: v1
kind: Secret
metadata:
  name: dashboard-admin
  namespace: kubernetes-dashboard
  annotations:
    kubernetes.io/service-account.name: "dashboard-admin"   
type: kubernetes.io/service-account-token
kubectl apply -f secret.yaml

Now execute the following command to retrieve the token for login.

kubectl get secret dashboard-admin -n kubernetes-dashboard -o jsonpath={".data.token"} | base64 -d

Access Kubernetes Dashboard

After completing these above steps, you should be able to access the Kubernetes Dashboard at https://kubernetes-dashboard.local and when prompted, enter the bearer token obtained in the previous step to log in.

Navigating the Kubernetes Dashboard

Once logged in, you will see the main dashboard interface. Here are some key areas to explore:

  • Workloads: Allows you to view and manage deployments, replica sets, jobs, and cron jobs.
  • Services and Ingress: Manage your services and ingress resources, essential for exposing your applications.
  • Config and Storage: Access and manage config maps, secrets, persistent volume claims, and storage classes.
  • Namespace Management: Switch between different namespaces to view and manage resources specific to each namespace.

Conclusion

The Kubernetes Dashboard is a powerful tool that simplifies cluster management and monitoring. By following the steps outlined in this guide, you can easily set up the Kubernetes Dashboard on Docker Desktop and start leveraging its capabilities.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles