6.0 KiB
Full cluster rebuild
Use this to rebuild the k3s cluster from new VMs. It destroys everything stored in the cluster. To change a running cluster, don't use this runbook.
This procedure has not been run end to end. Stop at any checkpoint that doesn't match, and don't work around it with
--forceor by clicking through a preview.
Why a normal pulumi up isn't enough
02-k8s-bootstrapcommands run once. They are recorded as done in state, so after new VMs appear,pulumi upwould report them unchanged and install nothing.03–06state describes the old cluster. The fixedclusterIdentifiertells Pulumi it is still the same cluster, so it would try to update resources that no longer exist.
Before you start
-
Save your data. Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes
heimdall-configand the Prometheus metrics. Grafana's database is external and is not affected. OpenBao's data is lost too, so save a snapshot outside the cluster and keep its unseal key and admin password. -
Stop automatic deploys. In Gitea's Actions tab, disable the
01,03,04,05and06workflows, and don't merge anything until the last step. -
Back up all state. Run this from the repo root:
mkdir -p ~/state-backups/rebuild for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring 06-openbao; do pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json doneThese backups describe the old cluster. Once its VMs are deleted, don't restore them.
-
Check what the rebuild depends on:
- pfSense is running, with the control-plane VIP and HAProxy configured. They are not managed by Pulumi. pfSense is VM 200 on the Optiplex, so if you reinstall that host, restore pfSense from a config backup first.
- The TrueNAS NFS share exists.
-
If you reinstalled any Proxmox host:
- Replace its CA in
02-k8s-bootstrap/certs/(pve1is B550,pve2is Optiplex,pve3is Esprimo). Get it withcat /etc/pve/pve-root-ca.pem, and never copy anything from/etc/pve/priv/. - Check that the host's certificate lists its current IP.
/etc/hostsmust have that IP before the certificate is generated. - Recreate the API token, then update the token and endpoint in
01-proxmox-infraconfig. Commit and push the change in.pulumi-config(see Stack config), because CI uses the pushed version. - The VM template on that host is gone too, so expect step 1 to recreate it.
- Replace its CA in
1. Recreate the VMs (01-proxmox-infra)
-
In Proxmox, delete the six
k3s-*VMs. Keep thek3s-ubuntu-noble-templateVMs. -
In pfSense, delete the six
k3s-*DHCP static mappings. New VMs get new MAC addresses. -
Sync state and preview:
pulumi refresh --stack dev --cwd 01-proxmox-infra pulumi preview --stack dev --cwd 01-proxmox-infraCheckpoint: the preview creates six VMs and six DHCP mappings, plus a template for any reinstalled host. It must show no replace or delete. These resources are protected, so if one is still in state after the refresh, find its URN with
pulumi stack --show-urnsand remove only that entry:pulumi state delete --force --stack dev --cwd 01-proxmox-infra '<urn>' -
Deploy. The VMs stay stopped until step 3.
pulumi up --stack dev --cwd 01-proxmox-infra
2. Clear the state of 02–06
Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or Pulumi.dev.yaml. --force is needed because 05-monitoring and 06-openbao protect their namespaces and Helm releases, so check that the old cluster is really gone before running it.
for S in 06-openbao 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do
pulumi state delete --all --force --yes --stack dev --cwd "$S"
done
Previews of 03–06 fail until step 3 is done, because 02 has no kubeconfig output yet.
3. Bootstrap k3s (02-k8s-bootstrap)
pulumi preview --stack dev --cwd 02-k8s-bootstrap
pulumi up --stack dev --cwd 02-k8s-bootstrap
Checkpoint: the preview only creates resources. The deploy starts the VMs, installs k3s on master-1, waits for the VIP, then joins the other nodes through it. If a step fails, fix the cause and run pulumi up again.
Check the new cluster with its own kubeconfig:
(umask 077; pulumi stack output kubeconfig --show-secrets --stack dev --cwd 02-k8s-bootstrap > ~/k3s-rebuilt.yaml)
KUBECONFIG=~/k3s-rebuilt.yaml kubectl get nodes
Secret encryption is configured with secretbox.
Checkpoint: all six nodes are Ready. Then replace your normal kubeconfig with this file, because the old one no longer works.
4. Deploy 03–06
Deploy these through Gitea, because the runners have the helm CLI that 03 needs. Re-enable each workflow as you reach it, and wait for each run to finish.
- Run the Deploy k8s Infra workflow manually.
- Run the Deploy k8s Apps workflow manually.
- Run the Deploy Monitoring workflow manually.
- Run the Deploy Openbao workflow manually, then restore the OpenBao snapshot.
5. Verify
kubectl get nodes
kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded
kubectl get pvc -A
kubectl get nodes.longhorn.io -n longhorn-system
kubectl get certificates -A
Checkpoint: nodes are Ready, no pods are unhealthy, PVCs are Bound, and certificates become Ready. New certificates come from Let's Encrypt, which rate-limits repeated requests for the same hostnames, so avoid repeated rebuilds in a short period.
Run pulumi preview --stack dev --cwd <stack> for all six stacks. None should show changes. Re-enable the 01 workflow, restore any data you saved, and delete ~/k3s-rebuilt.yaml and ~/state-backups/rebuild.