:.: Kubernetes dashboard

Hi there my fellow kubernetes lover, I am assuming you are here because already read my K3s clusterDuck over Alpine over OpenBSD log entry, and of course you just want a little bit more.

I will guide you a bit on the setup of the Web-ui-Dashboard, even on k3s you are able to enable the dashboard to get the information of your cluster.

Of course you have your cluster up and running, but let's make sure of it by getting our nodes:

$ kubectl get nodes -o wide 
NAME       STATUS   ROLES                  AGE   VERSION        INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
alpine02   Ready    worker                 57d   v1.24.4+k3s1   100.65.0.102           Alpine Linux v3.16   5.15.68-0-virt   containerd://1.6.6-k3s1
alpine03   Ready    worker                 57d   v1.24.4+k3s1   100.65.0.103           Alpine Linux v3.16   5.15.68-0-virt   containerd://1.6.6-k3s1
alpine01   Ready    control-plane,master   57d   v1.24.4+k3s1   100.65.0.101           Alpine Linux v3.16   5.15.68-0-virt   containerd://1.6.6-k3s1

Perfect! Let's get the recommended.yaml file from the kubernete's github repository, with thiswe'll be able to deploy the dashboard in our cluster

$ export GITHUB_URL=https://github.com/kubernetes/dashboard/releases
$ export VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
$ kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created

Wow, that was easy, I lo^C loonix, double check as always is needed, so time to get the pods:

$ kubectl get pods -n kubernetes-dashboard
NAME                                        READY   STATUS    RESTARTS   AGE
kubernetes-dashboard-67bd8fc546-wgksl       1/1     Running   0          85s
dashboard-metrics-scraper-8c47d4b5d-mnj87   1/1     Running   0          85s

Noice, time to create the admin user and it's role to be able to access the dashboard, for that we need to create 2 files, dashboard.admin-user.yml and dashboard.admin-user-role.yml:

$ cat dashboard.admin-user.yml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

$ cat dashboard.admin-user-role.yml
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

Final deploy (or apply) for those two:

$ kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml
serviceaccount/admin-user created

But... wait, where is my password? Ah! Right, you need to generate a token for it with the follow command:

$ kubectl -n kubernetes-dashboard create token admin-user     
eyJhbGciOiJSUzI1NiIsImtpZCI6IjRSeWtLWmZmN0FQa3lxRXNGcVZ3UlQyWHF4Zy1tZGR0SWtXZTZQR1FUdlUifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiLCJrM3MiXSwiZXhwIjoxNjY5MTM0MzAwLCJpYXQiOjE2NjkxMzA3MDAsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiMTQ3MWE0ZjMtM2FhMC00NTliLTgyMGEtOWU2YWUzNWY4NzhiIn19LCJuYmYiOjE2NjkxMzA3MDAsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.MzXoZw7CiWVLGvVI5aayN7P2CvOZAyfuVzvEizcbIKNjuJq6fW5oUXZKGYTd5uuO1v0bD_R8kD5nX2F3n9RWtJ_yoqsOCzVVu50jr5EJolgNO67WGZTRJpP8cTqz3KDtohoDbdTVVEk1Oyv17SarbyKH_ECNtuxHcz055G3Ps5I2Guy9W7t9rzped0s7TsIES8UA99gk_dB85y7ryiY-FyploVVk0k0F3Oi7BKfQUlkuk_TKNCsui48qs0p6Q_rglkQ9C8lkM_PGmCAGvahSTaAizxX2xHUZ6TDqBl_H_oQ6Y5xQ0IHgxIMe-ZSHqOqvfIFO_0bPyUDFggkRiWA-tw

To access the K3s Dashboard you must create a secure channel to your cluster with the kubectl's proxy:

$ kubectl proxy

Go to your browser and enter to http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login using the token we created above to login into it.

Kubernetes Dashboard

There you go, all the information of your cluster, plus much more, even the possibility to upload and deploy .yaml files to your cluster.