Skip to content

Latest commit

 

History

History

terraform

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Terraform - Hetzner k3s

This directory, contains terraform code to spin up a k3s cluster on Hetzner Cloud. (deployed using Terraform and kube-hetzner)

Pre-requisites

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:

SSH keys

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

Running the setup

Cluster

Setup the cluster in /cluster directory.

Initial setup - Creation of snapshots

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.

Cluster setup

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.

Content

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.