Setting Up Kubernetes-Dashboard On Local Docker-Desktop k8s & Access Via Ingress
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:
- Install latest version of docker desktop. Open the docker desktop dashboard. Kubernetes is not enabled by default.
2. Go to docker desktop settings. Select below options to enable local Kubernetes.
3. Local kubernetes installation starts.
4. The kubernetes tab shows green , once the local k8s cluster is up and running.
5. Following namespaces are available after first set up of k8s on docker desktop
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
7. A new namespace is created for kubernetes-dashboard on the k8s cluster.
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
8. A new namespace is created for nginx ingress on k8s
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
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
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
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}}"
15. Login into k8s dashboard using the generated token
15. k8s dashboard is now available for local kubernetes set up on docker-desktop, accessible via ingress.