From 8db7202686e2371b7242c4cb1db00f894a62f951 Mon Sep 17 00:00:00 2001 From: Urs Rudolph Date: Sun, 8 Mar 2026 13:24:06 +0100 Subject: [PATCH] Added Dashboard for kubernetes cluster --- README.md | 16 +++++++++ roles/dashboard/tasks/main.yml | 64 ++++++++++++++++++++++++++++++++++ roles/master/tasks/main.yml | 6 ++-- site.yml | 1 + 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 roles/dashboard/tasks/main.yml diff --git a/README.md b/README.md index d56e264..c5d29ee 100644 --- a/README.md +++ b/README.md @@ -94,3 +94,19 @@ After the playbook completes: kubectl get pods -A ``` Ensure `coredns` and `kube-flannel` are running. + +## Kubernetes Dashboard + +A dashboard has been installed and is accessible via NodePort on the master node. + +1. **Get the Token**: + Run this command on the master node to get your login token: + ```bash + kubectl get secret admin-user-token -n kubernetes-dashboard -o jsonpath={".data.token"} | base64 -d + ``` + +2. **Access the Dashboard**: + Open your browser and navigate to: + `https://:30443` + + *Note: Since it uses a self-signed certificate, you will need to bypass the browser security warning (usually click "Advanced" -> "Proceed").* diff --git a/roles/dashboard/tasks/main.yml b/roles/dashboard/tasks/main.yml new file mode 100644 index 0000000..689e9e5 --- /dev/null +++ b/roles/dashboard/tasks/main.yml @@ -0,0 +1,64 @@ +--- +- name: Install Metrics Server + command: kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml + environment: + KUBECONFIG: /etc/kubernetes/admin.conf + +- name: Patch Metrics Server for self-signed certs (RPi workaround) + command: > + kubectl patch deployment metrics-server -n kube-system --type='json' + -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--kubelet-insecure-tls"}]' + environment: + KUBECONFIG: /etc/kubernetes/admin.conf + +- name: Install Kubernetes Dashboard + command: kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml + environment: + KUBECONFIG: /etc/kubernetes/admin.conf + +- name: Create Dashboard Admin Service Account + shell: | + cat < + kubectl patch svc kubernetes-dashboard -n kubernetes-dashboard + -p '{"spec": {"type": "NodePort", "ports": [{"port": 443, "nodePort": 30443}]}}' + environment: + KUBECONFIG: /etc/kubernetes/admin.conf diff --git a/roles/master/tasks/main.yml b/roles/master/tasks/main.yml index ffce079..f107ab5 100644 --- a/roles/master/tasks/main.yml +++ b/roles/master/tasks/main.yml @@ -26,13 +26,15 @@ - name: Install Flannel Pod Network command: kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml - become: yes - become_user: "{{ ansible_user }}" + environment: + KUBECONFIG: /etc/kubernetes/admin.conf when: kubeadm_init.changed - name: Get join command command: kubeadm token create --print-join-command register: join_command_raw + environment: + KUBECONFIG: /etc/kubernetes/admin.conf - name: Add dummy host with variable add_host: diff --git a/site.yml b/site.yml index 79a920b..a96365e 100644 --- a/site.yml +++ b/site.yml @@ -10,6 +10,7 @@ become: yes roles: - master + - dashboard - name: Setup Worker Nodes hosts: workers