From 89fa7563058fe3e05d298ff0275c5ec7d5c82b7b Mon Sep 17 00:00:00 2001 From: juvdiaz Date: Thu, 28 May 2026 12:49:34 -0600 Subject: [PATCH] Label worker nodes before Prometheus migration --- README.md | 8 +++++--- lab.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2f6b7c4..bb7760d 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,8 @@ duplicate those PV manifests when you want storage on another node. `bootstrap/cluster` labels nodes with homelab placement metadata: +- `node-role.kubernetes.io/worker=worker` on every worker so `kubectl get nodes` + shows `worker` instead of `` in the ROLES column - `homelab.dev/node-role=control-plane` and `homelab.dev/storage=local` on the Debian control plane - `homelab.dev/node-role=edge-app` and `homelab.dev/storage=local` on the @@ -230,9 +232,9 @@ default `prometheus_stack_node_selector` (`homelab.dev/node-role=app` and `homelab.dev/storage=nvme`). Because the Prometheus, Alertmanager, and Grafana PVCs use retained local OpenEBS volumes, moving an existing install off the Debian control plane requires discarding those PVCs. Run -`./lab.sh move-prometheus-stack-workers` from the Debian host to destroy only -the existing `prometheus-stack` Helm release, delete its retained PVC/PV objects, -and recreate the stack on the worker selector. +`./lab.sh move-prometheus-stack-workers` from the Debian host to label existing +worker nodes, destroy only the existing `prometheus-stack` Helm release, delete +its retained PVC/PV objects, and recreate the stack on the worker selector. The website and demos NodePorts are reachable from the OCI jump box through the Raspberry Pi Tailscale interface. `bootstrap/cluster` installs a persistent diff --git a/lab.sh b/lab.sh index 27698ef..0201666 100755 --- a/lab.sh +++ b/lab.sh @@ -174,6 +174,49 @@ adopt_apps_existing_resources() { "demos-static" } +ensure_homelab_node_labels() { + local control_plane_node="${LAB_CONTROL_PLANE_NODE_NAME:-debian}" + local raspberry_node="${LAB_RASPBERRY_NODE_NAME:-raspberry}" + local prometheus_selector="homelab.dev/node-role=app,homelab.dev/storage=nvme" + local node + local target_nodes + + echo "Applying homelab labels to existing Kubernetes nodes..." + while IFS= read -r node; do + [[ -n "${node}" ]] || continue + + if [[ "${node}" == "${control_plane_node}" ]]; then + kubectl --kubeconfig "${KUBECONFIG_PATH}" label node "${node}" \ + homelab.dev/node-role=control-plane \ + homelab.dev/storage=local \ + --overwrite + continue + fi + + kubectl --kubeconfig "${KUBECONFIG_PATH}" label node "${node}" \ + node-role.kubernetes.io/worker=worker \ + --overwrite + + if [[ "${node}" == pimox-worker-* ]]; then + kubectl --kubeconfig "${KUBECONFIG_PATH}" label node "${node}" \ + homelab.dev/node-role=app \ + homelab.dev/storage=nvme \ + --overwrite + elif [[ "${node}" == "${raspberry_node}" ]]; then + kubectl --kubeconfig "${KUBECONFIG_PATH}" label node "${node}" \ + homelab.dev/node-role=edge-app \ + homelab.dev/storage=local \ + --overwrite + fi + done < <(kubectl --kubeconfig "${KUBECONFIG_PATH}" get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}') + + target_nodes="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" get nodes -l "${prometheus_selector}" -o name)" + if [[ -z "${target_nodes}" ]]; then + echo "No nodes match ${prometheus_selector}; refusing to move prometheus-stack." >&2 + exit 1 + fi +} + delete_prometheus_stack_storage() { local namespace="${1:-monitoring}" local pattern='(^|-)prometheus-stack-(prometheus|alertmanager|grafana)(-|$)|^prometheus-prometheus-stack|^alertmanager-prometheus-stack|^storage-prometheus-stack-grafana' @@ -227,6 +270,7 @@ move_prometheus_stack_workers() { export KUBECONFIG="${TF_VAR_kubeconfig_path}" echo "Moving prometheus-stack off the control plane. Existing prometheus-stack PVC data will be deleted." + ensure_homelab_node_labels tofu -chdir="${REPO_ROOT}/${stack}" init adopt_platform_existing_resources tofu -chdir="${REPO_ROOT}/${stack}" destroy -target=helm_release.prometheus_stack -auto-approve @@ -647,8 +691,8 @@ write_cluster_worker_var_file() { LAB_RASPBERRY_USER="${LAB_RASPBERRY_USER:-jv}" \ LAB_RASPBERRY_NODE_NAME="${LAB_RASPBERRY_NODE_NAME:-raspberry}" \ LAB_RASPBERRY_SSH_KEY_PATH="${LAB_RASPBERRY_SSH_KEY_PATH:-/home/jv/.ssh/id_ed25519}" \ - LAB_RASPBERRY_NODE_LABELS_JSON="${LAB_RASPBERRY_NODE_LABELS_JSON:-{\"homelab.dev/node-role\":\"edge-app\",\"homelab.dev/storage\":\"local\"}}" \ - LAB_PIMOX_WORKER_NODE_LABELS_JSON="${LAB_PIMOX_WORKER_NODE_LABELS_JSON:-{\"homelab.dev/node-role\":\"app\",\"homelab.dev/storage\":\"nvme\"}}" \ + LAB_RASPBERRY_NODE_LABELS_JSON="${LAB_RASPBERRY_NODE_LABELS_JSON:-{\"node-role.kubernetes.io/worker\":\"worker\",\"homelab.dev/node-role\":\"edge-app\",\"homelab.dev/storage\":\"local\"}}" \ + LAB_PIMOX_WORKER_NODE_LABELS_JSON="${LAB_PIMOX_WORKER_NODE_LABELS_JSON:-{\"node-role.kubernetes.io/worker\":\"worker\",\"homelab.dev/node-role\":\"app\",\"homelab.dev/storage\":\"nvme\"}}" \ python3 - "${spec_file}" "${var_file}" <<'PY' import json import os