own-proxy decision, terraform provisioner, system diagram, gateway SSE notes, server-budget comment and roadmap 0.4.0 now use Caddy with ACME-managed TLS instead of nginx plus certbot
54 lines
2.0 KiB
Markdown
54 lines
2.0 KiB
Markdown
# Server provisioning
|
|
|
|
Terraform owns everything outside the cluster: packages, swap, k3s itself,
|
|
the reverse proxy, and DNS records. Rebuilding the server from nothing is two
|
|
commands.
|
|
|
|
## Scope
|
|
|
|
| Layer | Managed by | Examples |
|
|
|---|---|---|
|
|
| Server, packages, swap, k3s install | Terraform (SSH provisioner, cloud-init or shell) | `fallocate`, `mkswap`, k3s service with trimmed config |
|
|
| DNS records | Terraform provider for the DNS zone | A/AAAA record for the apex domain |
|
|
| Reverse proxy | Terraform-managed Caddy, Caddyfile templated | reverse_proxy block to the gateway |
|
|
| Workloads inside k3s | kustomize, applied by CI or hand | Namespace `cv`, Deployments, Jobs, Services, quota |
|
|
|
|
Terraform does not manage anything inside the cluster. Kubernetes already
|
|
describes its own state; Terraform and kubectl would fight over it.
|
|
|
|
## Files
|
|
|
|
```
|
|
terraform/
|
|
main.tf server: packages, swap, k3s, Caddy
|
|
dns.tf A record for the apex domain
|
|
variables.tf server IP, SSH key, domain
|
|
outputs.tf server IP, proxy URL
|
|
```
|
|
|
|
Plan output for one run:
|
|
|
|
```
|
|
+ swapfile 2 GB
|
|
+ k3s service (traefik, servicelb disabled)
|
|
+ Caddy reverse_proxy block -> http://127.0.0.1:8080 (gateway NodePort)
|
|
+ certificate for noelsabia.dev
|
|
```
|
|
|
|
## Why
|
|
|
|
- The server became disposable: `terraform destroy && terraform apply` plus
|
|
`kubectl apply -k deploy/` returns the whole system. That is the fastest
|
|
possible disaster recovery and the clearest possible demo.
|
|
- Proxmox and cloud names change; code does not. The same Terraform targets the
|
|
home server now and a VM later.
|
|
- Home IP changes: the DNS provider has an A record the server can update.
|
|
Terraform manages the record; a small script re-sets it if the IP moves.
|
|
|
|
## Constraints
|
|
|
|
- **Terraform is new tooling** for Noel and needs approval under the stack
|
|
rule. Worth it: infrastructure as code is a core work skill.
|
|
- State file: local, not in Git. Nothing secret in the config itself.
|
|
- Changing a completed chapter or a Job is a delete plus apply, documented.
|