Setting Up Hetzner Cloud Provider for RKE2
Introduction
The Hetzner Cloud Provider for RKE2 allows seamless integration with Hetzner’s cloud infrastructure, enabling automatic provisioning of LoadBalancer services and persistent storage using Hetzner’s CSI driver.
This guide covers the necessary steps to set up the Hetzner Cloud Provider in an RKE2 cluster, ensuring full compatibility with Kubernetes networking and storage requirements.
Prerequisites
Before proceeding, ensure the following prerequisites are met:
- A Hetzner Cloud account with an active project.
- An RKE2 cluster running on Hetzner Cloud instances.
- API Token for Hetzner Cloud.
- Kubernetes CLI (
kubectl
) installed. - Helm installed on your local machine.
Step 1: Create an API Token
- Log in to your Hetzner Cloud account.
- Navigate to Access > API Tokens.
- Click Generate API Token.
- Assign necessary permissions (Read & Write for networking and storage).
- Copy and securely store the generated API token.
Step 2: Deploy the Hetzner Cloud Controller Manager (CCM)
- Add the Hetzner Helm repository:
helm repo add hetzner https://helm.hetzner.cloud helm repo update
- Create a
values.yaml
file for the Helm deployment:apiToken: "YOUR_HETZNER_API_TOKEN" network: "your-network-id" location: "nbg1"
- Install the CCM using Helm:
helm install hcloud-cloud-controller hetzner/hcloud-cloud-controller-manager -n kube-system -f values.yaml
Step 3: Configure the Hetzner CSI Driver
- Install the CSI driver via Helm:
helm install hcloud-csi hetzner/hcloud-csi-driver -n kube-system
- Verify that the driver is running:
kubectl get pods -n kube-system | grep hcloud
Step 4: Deploy a LoadBalancer Service
Create a sample LoadBalancer service:
apiVersion: v1
kind: Service
metadata:
name: hetzner-lb
annotations:
load-balancer.hetzner.cloud/location: "nbg1"
load-balancer.hetzner.cloud/use-private-ip: "true"
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
Apply the service:
kubectl apply -f hetzner-lb.yaml
Step 5: Verify Configuration
- Check if the LoadBalancer is provisioned:
kubectl get svc hetzner-lb
- Test persistent volume provisioning:
kubectl get storageclass | grep hcloud
- Ensure nodes have the correct provider ID:
kubectl describe nodes | grep "ProviderID"
Conclusion
The Hetzner Cloud Provider enables seamless integration with RKE2, automating networking and storage management. By setting up CCM and CSI, you can efficiently deploy LoadBalancer services and use Hetzner’s block storage with Kubernetes workloads.
For more Kubernetes and RKE2 training, check out other training posts.