An opinionated Terraform module for deploying a Hetzner Kubernetes Cluster using RKE2 and Hetzner Cloud.
Personally, I host everything on Hetzner and always found that Hetzner is a really great choice for many use cases. Lately I've been experimenting with Kubernetes and needed my personal development cluster, and since most cloud providers are really expensive for personal use, I created this module. Using it I can deploy a K8s cluster really easy that is not that expensive. Because this module was created for my personal needs, it is really opinionated about the technologies used, and not really customizable yet. However, in the future, I want to make this module more suited for general use, and more customizable.
- RKE2 as the kubernetes distribution
- Use of Hetzner Private Networks to reduce latency
- Integration with Hetzner Cloud Controller Manager
- NGINX Ingress controller using a Hetzner Load Balancer
- Including cert-manager configured using LetsEncrypt
- Cilium as the Kubernetes CNI
- Hetzner CSI for the storage interface
- Proper use of Hetzner Firewalls to only allow required traffic
- Installation happens using cloud-init
There are two features that I would definitely like to support in the future:
- High Availability (having multiple master nodes)
- Cluster autoscaling to allow nodes to be spawned on-demand
- Create a new Hetzner Cloud project and generate an API token
- (optional) Generate a new SSH key, or copy your existing public SSH key. This is optional, because this module will generate it's own SSH key which you can use.
- Copy the
template.tf.example
file to a new, empty directory and fill in your values. - Deploy the cluster using the following commands. Note that this can take quite some time because it takes a while until the master node is started.
terraform init
terraform apply
- Get the kubeconfig output from Terraform using
terraform output -raw kubeconfig > ~/.kube/config
. - Run
kubectl get nodes
and check for all running nodes. Output should look something like this: You may be wondering that some agent nodes do not show up yet. This is because the module does not wait for all agents to finish their setup process, so just wait a minute and they should appear :)