Cluster API Provider Hetzner (CAPH)
repository·main·Indexed 22 days ago
https://github.com/syself/cluster-api-provider-hetznerA Cluster API provider for the declarative management of self-managed Kubernetes clusters on Hetzner Cloud and Hetzner Bare Metal infrastructure. It enables automated deployment and lifecycle management, supporting both cloud and bare-metal instances. The documentation covers management cluster setup using clusterctl, workload cluster generation, HCloud secret configuration, and the installation of Cilium CNI and Cloud Controller Managers (CCM).
What's inside cluster-api-provider-hetzner
- Cluster API Provider Hetzner (CAPH) is a Kubernetes Cluster API provider designed to automate the deployment and lifecycle management of self-managed Kubernetes clusters on Hetzner infrastructure. It supports both cloud and bare-metal instances, providing a consistent and scalable way to manage production-ready clusters.
How the default CSR controller works
mainTo ensure secure operation, Kubernetes requires signing kubelet serving certificates. When the kubelet flag
rotate-server-certificates: "true"is set (configured viainitConfiguration/joinConfiguration.nodeRegistration.kubeletExtraArgs), the kubelet automatically submits a Certificate Signing Request (CSR) to the Kubernetes certificates API.CAPH includes a built-in CSR controller that automatically approves these requests. The controller validates the request by checking the DNS name and the IP address to ensure only the intended nodes receive signed certificates.
Important Configuration Note: To avoid errors with the default controller, do not manually set the following kubelet flags:
tls-cert-file: "/var/lib/kubelet/pki/kubelet-client-current.pem"tls-private-key-file: "/var/lib/kubelet/pki/kubelet-client-current.pem"
# Do NOT set these flags if you want to use the default CSR controller tls-cert-file: "/var/lib/kubelet/pki/kubelet-client-current.pem" tls-private-key-file: "/var/lib/kubelet/pki/kubelet-client-current.pem"Manage the lifecycle of a HetznerBareMetalHost
mainThe lifecycle of a host follows these stages:
- Creation: The host is available for consumption immediately after creation.
- Consumption: A
HetznerBareMetalMachineselects the host, updating the host's status and triggering provisioning. - Deprovisioning: When the consuming
HetznerBareMetalMachineis deleted, the host deprovisions and returns to a neutral state. - Deletion: A host can only be deleted when it is in a neutral state. To safely delete a host that is currently in use, you must first enable
maintenanceModeto ensure no machines consume it.
Understand HetznerCluster modes
mainThe
HetznerClusterobject supports two primary deployment modes:- HCloud Cluster: Uses Hetzner Cloud (HCloud) instances. It works with
kubeadmand supports private networks. - Bare Metal Cluster: Uses Hetzner dedicated servers for either control planes or workers.
Important constraints for Bare Metal clusters:
- Private networks are not supported for bare metal clusters.
- Node images must support
cloud-initfor provisioning. - You can use either the Syself CCM or the upstream HCloud CCM. Ensure your
ProviderIDformat matches the requirements for your chosen CCM.
- HCloud Cluster: Uses Hetzner Cloud (HCloud) instances. It works with
How HetznerBareMetalMachine and HetznerBareMetalHost interact
mainThe
HetznerBareMetalMachinelifecycle is managed by theHetznerBareMetalMachineController. Crucially, the controller does not create or delete physical Hetzner dedicated machines directly. Instead, it operates on an inventory of existingHetznerBareMetalHosts(which represent already existing bare metal servers).Provisioning Flow:
- A
HetznerBareMetalMachineis created with specs defined in aHetznerBareMetalMachineTemplate. - The machine uses selectors to pick an available
HetznerBareMetalHost. - If a host is selected and not yet consumed, the machine transfers provisioning information to that host.
- The host is provisioned according to the template specs. Once successful, the machine is marked as
ready.
Deprovisioning Flow:
- When a
HetznerBareMetalMachineis deleted, it removes provisioning information from the associated host. - The host triggers deprovisioning.
- Once deprovisioning completes, the controller removes the owner/consumer references and finalizers, allowing the machine object to be fully deleted.
- A
Run multiple Kubernetes clusters in a single Hetzner project
mainThe
cluster-api-provider-hetznersupports multi-tenancy, allowing you to run multiple Kubernetes clusters within the same Hetzner cloud project simultaneously.To ensure isolation and prevent resource conflicts, the controller uses labels on all provisioned Hetzner resources that correspond to the specific cluster name. This labeling mechanism allows the controller to manage and distinguish resources belonging to different clusters even when they reside in the same project.
Understand the relationship between CAPH and CAPI objects
mainWhen working with the Cluster API Provider Hetzner (CAPH), it is important to distinguish between standard Cluster API (CAPI) objects and the provider-specific objects that implement them.
HetznerClusteris the provider-specific counterpart to the CAPIClusterobject.- CAPI's
Machineobject is implemented by either anHCloudMachineor aHetznerBareMetalMachine, depending on the infrastructure type.
Configure HetznerBareMetalRemediationTemplate
mainThe
HetznerBareMetalRemediationTemplateallows you to define custom methods for how Machine Health Checks treat unhealthyHetznerBareMetalMachineobjects. These templates are reconciled by theHetznerBareMetalRemediationController, which triggers the specified remediation on the relevant machine.To use this, you must define a
strategywithin thespec. Currently, only theRebootstrategy type is supported.Choose a Hetzner Bare Metal flavor for Cluster API
mainWhen deploying clusters using bare metal servers with CAPH, you can select from different pre-defined templates known as 'flavors'. These flavors determine whether control plane nodes run on bare metal or HCloud (virtualized) and how the cluster handles machine remediation (recovery from failure).
Note: These flavors are intended for demonstration purposes and are not recommended for production environments.
# Flavors are consumed using the clusterctl tool # Example usage pattern (conceptual): clusterctl generate cluster --flavor <flavor-name> ...High Availability components in CAPH
mainA standard CAPH installation managed via
clusterctlinvolves four primary components. While the default installation is not highly available, these components can be scaled to improve reliability:- Cluster API (CAPI): The core management layer.
- cluster-api-bootstrap-provider-kubeadm (CAPBK): Handles the bootstrapping of nodes.
- cluster-api-control-plane-kubeadm (KCP): Manages the control plane lifecycle.
- cluster-api-provider-hetzner (CAPH): The infrastructure provider for Hetzner.
Understand the HetznerBareMetalHost object
mainThe
HetznerBareMetalHostobject represents a one-to-one relationship with a Hetzner dedicated server. It is used to make bare metal servers available to clusters.Key characteristics:
- Decoupled from Clusters: A host object does not belong to a specific
HetznerClusterand can be used by multiple clusters. This allows you to track server availability independently. - Immutability: Host objects cannot be updated. If you need to change a property, you must delete the existing object and create a new one.
- Provisioning Trigger: Provisioning is triggered when a
HetznerBareMetalMachineselects the host and updates its status.
- Decoupled from Clusters: A host object does not belong to a specific
Manage SSH keys for Hetzner Robot bare metal servers
mainBare metal servers in Hetzner Robot require two SSH keys: one for the rescue system and one for the actual system. These keys are managed via Kubernetes Secrets containing both the public and private key data.
Configuration Locations:
- Rescue System Key: Defined cluster-wide in the
HetznerClusterspecification. - Actual System Key: Defined in the
HetznerBareMetalMachineTemplate. There is no cluster-wide alternative for the actual system key.
Important Lifecycle Notes:
- You cannot change the reference to the secret in the spec, but you can update the data within the secret itself.
- Provisioned Hosts: If a host is already provisioned, changing the secret data will trigger a warning event. Provisioned hosts cannot automatically update their SSH keys; you must delete and recreate the machine object to apply changes.
- Provisioning Hosts: If a host is currently in the provisioning state, it may restart the provisioning process if the SSH key change is necessary, depending on whether the rescue or actual system key was modified.
- Rescue System Key: Defined cluster-wide in the