Deploy Kubernetes cluster on Hetzner Cloud using the kube-hetzner/terraform-hcloud-kube-hetzner repository. This project aims to create a highly optimized, auto-upgradable, highly available and cost-effective Kubernetes cluster on Hetzner Cloud.
Before you begin, ensure you have the following:
- A Hetzner Cloud account. You can sign up for one here.
- The following command-line tools installed:
Generate a passphrase-less SSH key pair to be used for the cluster.
ssh-keygen -t ed25519 -N "" -f ~/.ssh/hcloud-kube-hetzner
- Create a project in your Hetzner Cloud Console and obtain an API key with "Read & Write" permissions.
- Navigate to the directory where you want to deploy the cluster and execute the following command to create your kube.tf file and the required MicroOS snapshot:
For bash:
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}"
For fish shell:
set 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}"; bash "{tmp_script}"; rm "{tmp_script}"
This command will help you set up a new folder with the required files and guide you through the creation of a needed MicroOS snapshot.
In your project folder, you will find the kube.tf
file. Customize this file to suit your needs, specifying variables such as the number of control-plane and agent nodes, CNI choice, and other cluster configurations. An example of a cube.tf
file is in the root of this repository.
Now that you have your kube.tf
file ready, initialize Terraform and apply the configuration:
cd <your-project-folder>
terraform init --upgrade
terraform validate
terraform apply -auto-approve
This process will take approximately 5 minutes to complete, and you will receive confirmation of a successful deployment.
Once the cluster is deployed, you can access and manage it:
-
To access the cluster details, use:
terraform output kubeconfig
-
To manage your cluster with
kubectl
, either SSH into a control-plane node or use the Kube API.
You can scale the number of nodes and node pools, configure add-ons, and manage the cluster as per your requirements. Refer to the project documentation for detailed information on these topics.
When you are finished with your cluster, you can destroy it and release the associated resources using Terraform:
terraform destroy -auto-approve
Alternatively, you can use the provided cleanup script for a more comprehensive cleanup:
tmp_script=$(mktemp) && curl -sSL -o "${tmp_script}" https://raw.githubusercontent.com/kube-hetzner/terraform-hcloud-kube-hetzner/master/scripts/cleanup.sh && chmod +x "${tmp_script}" && "${tmp_script}" && rm "${tmp_script}"
This script will remove all resources related to your cluster.
To upgrade the module to the latest version, modify the version attribute in your kube.tf
file and apply the configuration using Terraform.