Setting Up Kubernetes-Dashboard On Local Docker-Desktop k8s & Access Via Ingress

Prince Arora
4 min readDec 3, 2021

Problem Statement :

  • The docker-desktop on windows provides inbuilt single node kubernetes set up that can be enabled. But it provides no dashboard for kubernetes in the in built set up.
  • The k8s dashboard needs to be accessed from browser.
  • The k8s dashboard should be accessible via ingress instead of kubectl proxy

Solution :

  • Deploy the k8s dashboard on local k8s
  • Install the NGINX ingress controller on local k8s
  • Create ingress rules
  • Create user & token for login to dashboard

Steps:

  1. Install latest version of docker desktop. Open the docker desktop dashboard. Kubernetes is not enabled by default.
Docker Desktop Dashboard

2. Go to docker desktop settings. Select below options to enable local Kubernetes.

Docker Desktop Settings

3. Local kubernetes installation starts.

Local kubernetes installation in progress on docker-desktop

4. The kubernetes tab shows green , once the local k8s cluster is up and running.

Local k8s cluster setup done

5. Following namespaces are available after first set up of k8s on docker desktop

List namespaces in the k8s cluster

6. Deploy Kubernetes Dashboard : Execute following command and deploy k8s dashboard on the k8s cluster.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
Deploy k8s dashboard on the cluster

7. A new namespace is created for kubernetes-dashboard on the k8s cluster.

List namespaces in the k8s cluster. New namespace created for k8s-dashboard

7. Install nginx ingress controller on k8s: Execute the following command to install nginx ingress controller.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
Install nginx ingress controller on the local k8s cluster

8. A new namespace is created for nginx ingress on k8s

List namespaces in the k8s cluster. New namespace created for ingress-nginx

8. List all components in the ingress-nginx namespace. The nginx controller service is of type LoadBalancer and is exposed externally to receive requests for the API server in k8s

ingress-nginx namespace components

9. List all components in the kubernetes-dashboard namespace. The kubernetes dashboard service is internal and is exposed on port 443, which is https port

kubernetes-dashboard namespace components

10. Create the following ingress rule. Ensure the ingress rule is created in the kubernetes-dashboard namespace and has the same servicename as for the kubernetes-dashboard. The port number should be of the kubernetes-dashboard service.

kubectl apply -f dashboard-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dashboard-ingress
namespace: kubernetes-dashboard
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
rules:
- host: k8s-dashboard.com
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: kubernetes-dashboard
port:
number: 443

11. Make following entry in the host file

127.0.0.1 k8s-dashboard.com

12. Access the kubernetes dashboard using following link

https://k8s-dashboard.com/#/login

k8s dashboard launched

13. Create admin user to access the dashboard

kubectl apply -f 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

14. Generate token to login into k8s dashboard

kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
Token generated to login into k8s dashboard

15. Login into k8s dashboard using the generated token

k8s dashboard

15. k8s dashboard is now available for local kubernetes set up on docker-desktop, accessible via ingress.

k8s dashboard login successful

--

--

Prince Arora

IT professional | Technology enthusiast | Cloud | AWS | Docker | Machine Learning