This directory, contains terraform code to spin up a k3s cluster on Hetzner Cloud. (deployed using Terraform and kube-hetzner)
The following software needs to be installed on your local machine:
- Terraform / OpenTofu
- Packer (For initial setup of snapshots for the servers)
- Kubectl (For interacting with the Kubernetes cluster)
- hcloud cli tool (For interacting with the Hetzner Cloud API)
- SSH client (For connecting to the servers)
The following services are required, in order to deploy the Kubernetes cluster:
- Hetzner Cloud account
- Hetzner Cloud API Token (For authenticating with the Hetzner Cloud API)
- Cloudflare account
- Cloudflare API Token (For authenticating with the Cloudflare API)
- Cloudflare controlled domain (For allowing the system to allocate a domain for the Kubernetes cluster)
In order to connect to the servers, you need to have an SSH key pair. The keys path needs to be set in the tfvars file.
The SSH key should be ssh-ed25519 or rsa-sha2-512 (for easy use, passphrase-less)
ssh-keygen -t ed25519
Setup the cluster in /cluster
directory.
In order to create the cluster, we need to create snapshots of the servers that will be used in the cluster. This is done by running the following command (say yes, to build snapshots using packer):
tmp_script=$(mktemp) && curl -sSL -o "${tmp_script}" https://raw.githubusercontent.com/kube-hetzner/terraform-hcloud-kube-hetzner/master/scripts/create.sh && chmod +x "${tmp_script}" && "${tmp_script}" && rm "${tmp_script}"
Note: This will create a snapshot of the server, which will be used as the base image for the Kubernetes cluster, as well as ensuring local software is installed.
The software has been provided by the kube-hetzner project.
Configure the tfvars/template.tfvars
file with the required values.
Then run the following command to create the Kubernetes cluster:
tofu init
tofu apply --var-file tfvars/template.tfvars
Now, watch the cluster being created.
Setup the content of the cluster in /content
directory.
Configure the tfvars/template.tfvars
file with the required values.
You will need to export the KUBECONFIG variable to the correct file, in order to interact with the cluster, even though Teraform does require a file to be set.
export KUBECONFIG=$(pwd)/../cluster/k3s_kubeconfig.yaml
Then run the following command to create the Kubernetes cluster:
tofu init
tofu apply --var-file tfvars/template.tfvars
Now, watch the content being deployed.