# 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 `--force` or by clicking through a preview. ## Why a normal `pulumi up` isn't enough - **`02-k8s-bootstrap` commands run once.** They are recorded as done in state, so after new VMs appear, `pulumi up` would report them unchanged and install nothing. - **`03`–`05` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist. ## Before you start 1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected. 2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04` and `05` workflows, and don't merge anything until the last step. 3. **Back up all state.** Run this from the repo root: ```bash mkdir -p ~/state-backups/rebuild for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring; do pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json done ``` These backups describe the old cluster. Once its VMs are deleted, don't restore them. 4. **Check what the rebuild depends on:** - pfSense is running, with the [control-plane VIP and HAProxy](pfsense-control-plane-vip.md) 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](truenas-nfs.md) exists. 5. **If you reinstalled any Proxmox host:** - Replace its CA in `02-k8s-bootstrap/certs/` (`pve1` is B550, `pve2` is Optiplex, `pve3` is Esprimo). Get it with `cat /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/hosts` must have that IP before the certificate is generated. - Recreate the API token, then update the token and endpoint in `01-proxmox-infra` config. Commit and push the change in `.pulumi-config` (see [Stack config](../../README.md#stack-config)), because CI uses the pushed version. - The VM template on that host is gone too, so expect step 1 to recreate it. ## 1. Recreate the VMs (`01-proxmox-infra`) 1. In Proxmox, delete the six `k3s-*` VMs. Keep the `k3s-ubuntu-noble-template` VMs. 2. In pfSense, delete the six `k3s-*` DHCP static mappings. New VMs get new MAC addresses. 3. Sync state and preview: ```bash pulumi refresh --stack dev --cwd 01-proxmox-infra pulumi preview --stack dev --cwd 01-proxmox-infra ``` **Checkpoint:** 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-urns` and remove only that entry: ```bash pulumi state delete --force --stack dev --cwd 01-proxmox-infra '' ``` 4. Deploy. The VMs stay stopped until step 3. ```bash pulumi up --stack dev --cwd 01-proxmox-infra ``` ## 2. Clear the state of `02`–`05` 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` protects its namespace and Helm release, so check that the old cluster is really gone before running it. ```bash for S in 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`–`05` fail until step 3 is done, because `02` has no `kubeconfig` output yet. ## 3. Bootstrap k3s (`02-k8s-bootstrap`) ```bash 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: ```bash (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`, `04` and `05` 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. 1. Run the **Deploy k8s Infra** workflow manually. 2. Run the **Deploy k8s Apps** workflow manually. 3. Run the **Deploy Monitoring** workflow manually. ## 5. Verify ```bash 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 ` for all five stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`.