Deploying a Hetzner-Hosted Kubernetes Cluster with Karpenter Autoscaling via Terraform

Deploying a Hetzner-Hosted Kubernetes Cluster with Karpenter Autoscaling via Terraform

This guide fills the gap by combining Hetzner Cloud infrastructure provisioning, Kubernetes control-plane deployment, and Karpenter-based autoscaling—all in Terraform.

Summary

While there are standalone tutorials for spinning up Kubernetes on Hetzner with Terraform and separate guides for Karpenter on AWS, no single resource walks through the entire flow on Hetzner with Karpenter autoscaling via Terraform [oai_citation:0‡qovery.com](https://www.qovery.com/blog/autoscaling-amazon-eks-with-karpenter-a-step-by-step-guide/?utm_source=chatgpt.com) [oai_citation:1‡Amazon Web Services, Inc.](https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/?utm_source=chatgpt.com). In this post, we’ll:

  • Provision Hetzner resources with the official hcloud Terraform provider [oai_citation:2‡Terraform Registry](https://registry.terraform.io/providers/hetznercloud/hcloud?utm_source=chatgpt.com).
  • Deploy a production-grade cluster using the terraform-hcloud-kube-hetzner module [oai_citation:3‡GitHub](https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner?utm_source=chatgpt.com).
  • Install Karpenter via Helm and configure a Custom Provisioner for Hetzner [oai_citation:4‡Karpenter](https://karpenter.sh/docs/getting-started/getting-started-with-karpenter/?utm_source=chatgpt.com).
  • Leverage kOps’s experimental Hetzner+Karpenter integration as a reference for building your own provider extension [oai_citation:5‡kOps](https://kops.sigs.k8s.io/releases/1.24-notes/?utm_source=chatgpt.com) [oai_citation:6‡GitHub](https://github.com/kubernetes-sigs/karpenter/issues/741?utm_source=chatgpt.com).

1. Prerequisites

  • Hetzner Cloud API token with sufficient rights [oai_citation:7‡qovery.com](https://www.qovery.com/blog/autoscaling-amazon-eks-with-karpenter-a-step-by-step-guide/?utm_source=chatgpt.com).
  • Terraform CLI v1.4+ installed locally.
  • SSH keypair for node access.
  • kubectl and helm installed.
  • Basic familiarity with Kubernetes, Helm, and Terraform.

2. Step 1: Provisioning Hetzner Infrastructure

Begin by configuring the official Hetzner Cloud provider in Terraform:

provider "hcloud" {
  token = var.hcloud_token
}
      
This provider lets you manage networks, servers, volumes, and more on Hetzner Cloud [oai_citation:8‡Terraform Registry](https://registry.terraform.io/providers/hetznercloud/hcloud?utm_source=chatgpt.com). Next, define a virtual network, SSH key, and security group for your cluster nodes.

3. Step 2: Deploying the Kubernetes Control Plane

We recommend the kube-hetzner/terraform-hcloud-kube-hetzner module for a secure, production-ready cluster setup. It automates control-plane and worker creation, networking, and kubeconfig output [oai_citation:9‡GitHub](https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner?utm_source=chatgpt.com). Example usage:

module "k8s" {
  source = "github.com/kube-hetzner/terraform-hcloud-kube-hetzner"
  ssh_key = hcloud_ssh_key.cluster.id
  node_count = 3
  network_id = hcloud_network.cluster.id
}
      

4. Step 3: Installing Karpenter

Add the official Karpenter Helm repository and install the controller in your cluster:

helm repo add karpenter https://charts.karpenter.sh
helm repo update
helm install karpenter karpenter/karpenter \
  --namespace karpenter --create-namespace \
  --set serviceAccount.create=true \
  --set settings.aws.clusterName="${module.k8s.cluster_name}" \
  --set settings.aws.clusterEndpoint="${module.k8s.endpoint}"
      
This deploys Karpenter v1.4+, which observes unschedulable pods and provisions new nodes just-in-time [oai_citation:10‡Karpenter](https://karpenter.sh/docs/getting-started/getting-started-with-karpenter/?utm_source=chatgpt.com) [oai_citation:11‡Karpenter](https://karpenter.sh/docs/getting-started/getting-started-with-karpenter/?utm_source=chatgpt.com).

5. Step 4: Configuring the Hetzner Provisioner

Karpenter currently includes first-class AWS support, but is architected for other clouds as well [oai_citation:12‡Karpenter](https://karpenter.sh/docs/faq/?utm_source=chatgpt.com). To bridge the gap on Hetzner, you can:

  1. Use kOps experimental support: kOps v1.24+ allows managing Hetzner clusters with Karpenter as the instance manager—see --instance-manager=karpenter [oai_citation:13‡kOps](https://kops.sigs.k8s.io/releases/1.24-notes/?utm_source=chatgpt.com).
  2. Custom provider plugin: follow the Karpenter cloudprovider guide and adapt the AWS provider code to Hetzner’s Hcloud API [oai_citation:14‡GitHub](https://github.com/kubernetes-sigs/karpenter/issues/741?utm_source=chatgpt.com).
Whichever path you choose, define a KarapatanProvisioner CRD that matches your node requirements (labels, taints, resources) and targets your Terraform-managed server group via a shared tag or label.

6. Step 5: Validating Autoscaling

Apply a test deployment with a high replica count:

kubectl apply -f - <
      Watch Karpenter provision new nodes and schedule pods within seconds  [oai_citation:15‡qovery.com](https://www.qovery.com/blog/autoscaling-amazon-eks-with-karpenter-a-step-by-step-guide/?utm_source=chatgpt.com).
    

Ready to Streamline Your Kubernetes Autoscaling?

Download the complete Terraform & Helm templates and join our expert community to get best practices on Hetzner + Karpenter deployments today!

Stay ahead in cloud-native operations—follow us for more deep dives!

#Hetzner #Kubernetes #Terraform #Karpenter #Autoscaling #CloudNative


Leave a Reply

Your email address will not be published. Required fields are marked *