This repository contains terraform modules used to setup a Kubernetes development environment in Hetzner Cloud.
Warning
This project is not an official Hetzner Cloud Integration and is intended to be used internally. There is no backwards-compatibility promise.
The environment is split in two modules that must be used in two separate states:
| Module | Manages |
|---|---|
modules/infra |
Hetzner Cloud resources (SSH key, network, servers) and the k3s cluster running on them. |
modules/k8s |
Resources inside the cluster (hcloud Secret, Cilium, hccm, csi-driver, Docker registry). |
The kubernetes and helm providers of the k8s module are configured from an input variable, and never from an attribute of a resource in the same state. Terraform can therefore always plan and destroy the in-cluster resources, even while the cluster is being replaced or is already gone. Recreating the cluster (e.g. when changing the k3s version) simply recreates the in-cluster resources on the next apply, instead of stranding them in a state that points at a cluster that no longer exists.
The infra state must be applied before the k8s state, and destroyed after it. See example/ for the wiring between both states, done with a terraform_remote_state data source.
To setup a development environment, make sure you installed the following tools:
- Configure a
HCLOUD_TOKENin your shell session.
Warning
The development environment runs on Hetzner Cloud servers which will induce costs.
- Deploy the development cluster:
make -C example up- Load the generated configuration to access the development cluster:
source example/files/env.sh- Check that the development cluster is healthy:
kubectl get nodes -o widemake -C example down