Deploying OKD (OpenShift Origin Community Distribution) in a high-availability (HA) configuration across three different Hetzner Cloud locations with Terraform is a non-trivial but highly valuable setup for fault-tolerant Kubernetes infrastructure. Below, I’ll provide a step-by-step guide following industry best practices, leveraging Terraform, Ansible, HAProxy or external load balancing, and Hetzner Cloud Load Balancer (where needed).
🔧 Assumptions and Tools
| Component | Purpose |
|---|
| OKD | Origin Kubernetes Distribution (Open Source OpenShift) |
| Terraform | Infrastructure as Code (Hetzner provisioning) |
| Ansible | Provisioning and configuration of OS and OKD components |
| HAProxy or Hetzner Load Balancer | API Load Balancer for HA API endpoints |
| Fedora CoreOS | OS for OKD nodes |
| Hetzner Cloud | Cloud infrastructure |
🌍 High-Level Architecture
- Master/API/Control Plane Nodes: 3 nodes in 3 different Hetzner locations (NBG1, HEL1, FSN1) for HA.
- Worker Node: 1 or more worker nodes (can be scaled later).
- Load Balancer: External LB for
api.<domain> and apps.<domain> routing to master/worker nodes.
- DNS and SSL should be managed properly for external access.
☁️ Step-by-Step Deployment Guide
Step 1: Prerequisites
-
Install required tools
brew install terraform hetznercloud ansible hcloud hcloud-cli
-
Hetzner configuration
-
Generate SSH key for instance logins:
ssh-keygen -t ed25519 -C "okd-cloud"
-
Set up a DNS domain – critical for routing and certs. You will need to:
api.okd.yourdomain.com → points to API Load Balancer.
*.apps.okd.yourdomain.com → points to Ingress Load Balancer.
Step 2: Prepare Terraform Script for Hetzner Cloud
Repo structure:
okd-ha-hetzner/
├── terraform/
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── provider.tf
provider.tf
provider "hcloud" {
token = var.hcloud_token
}
variables.tf
variable "ssh_key_name" {
default = "okd-key"
}
variable "hcloud_token" {
type = string
default = ""
}
variable "locations" {
default = ["nbg1", "fsn1", "hel1"]
}
main.tf
resource "hcloud_ssh_key" "default" {
name = var.ssh_key_name
public_key = file("~/.ssh/id_ed25519.pub")
}
resource "hcloud_server" "masters" {
count = length(var.locations)
name = "master-${count.index}"
server_type = "cx41"
image = "fedora-36"
location = var.locations[count.index]
ssh_keys = [hcloud_ssh_key.default.id]
}
resource "hcloud_server" "worker" {
name = "worker-1"
server_type = "cx31"
image = "fedora-36"
location = var.locations[0]
ssh_keys = [hcloud_ssh_key.default.id]
}
resource "hcloud_load_balancer" "okd-api" {
name = "okd-api-lb"
load_balancer_type = "lb11"
location = var.locations[0]
}
resource "hcloud_load_balancer_target" "masters" {
count = length(var.locations)
load_balancer_id = hcloud_load_balancer.okd-api.id
type = "server"
server_id = hcloud_server.masters[count.index].id
}
Add firewall rules appropriately as per OKD documentation for ports like 6443, 22623, 443, 80 etc.
outputs.tf
output "master_ips" {
value = [for s in hcloud_server.masters : s.ipv4_address]
}
output "worker_ip" {
value = hcloud_server.worker.ipv4_address
}
output "loadbalancer_ip" {
value = hcloud_load_balancer.okd-api.ipv4
}
Step 3: Terraform Apply
cd terraform/
terraform init
terraform apply
Step 4: GUI DNS Setup
- Update your DNS entries:
api.okd.yourdomain.com → Load balancer IP
*.apps.okd.yourdomain.com → A record → Load balancer IP
Step 5: Bootstrap Ignition Files
Use Red Hat Assisted Installer or do FCOS pre-bootstrapping manually:
-
Install openshift-install (OKD):
-
Create install-config.yaml:
apiVersion: v1
baseDomain: yourdomain.com
metadata:
name: okd
compute:
- name: worker
replicas: 1
controlPlane:
name: master
replicas: 3
platform:
none: {}
platform:
none: {}
networking:
networkType: OVNKubernetes
clusterNetwork:
- cidr: 10.132.0.0/14
hostPrefix: 23
serviceNetwork:
- 172.30.0.0/16
pullSecret: '{"auths":{}}'
sshKey: |
ssh-ed25519 AAA...
- Generate manifests and ignition configs:
openshift-install create manifests --dir=okd-install
# (optional modify manifests)
openshift-install create ignition-configs --dir=okd-install
Step 6: Provisioning Fedora CoreOS (FCOS)
Use Ansible or cloud-init to provision master and worker nodes with the corresponding ignition files.
Each FCOS node should:
- Get
coreos.inst.ignition_url=https://yourserver/ignition/master.ign as a boot parameter,
- Can be booted using ISO or PXE with the above ignition file setup.
You can serve ignition via HTTP from a temporary provisioning server.
Step 7: Bootstrap the Cluster
-
Start bootstrapping node (first master), it will initiate the cluster.
-
Master nodes and worker nodes join the cluster via their ignition files.
-
Monitor via openshift-install wait-for bootstrap-complete --dir=okd-install.
Step 8: Finalizing the Setup
-
After bootstrap:
openshift-install wait-for install-complete --dir=okd-install
-
Log in:
export KUBECONFIG=okd-install/auth/kubeconfig
oc login ...
-
Access the OKD Web Console:
https://console-openshift-console.apps.okd.yourdomain.com
Step 9: Ingress Load Balancer
Repeat similar setup as you did with the API LB to serve *.apps.okd.yourdomain.com.
- Attach worker nodes to that LB.
- Use Let's Encrypt or internal cert.
- Point wildcard DNS to LB IP.
🔐 Best Practices
- Use Fedora CoreOS for OKD compatibility.
- Ensure firewalls only allow required ports.
- Use LoadBalancer health checks.
- Use
etcd encryption and backup strategies.
- Secure SSH access with private networking or VPN.
- Automate via CI/CD (GitHub Actions, ArgoCD optionally).
🧱 Optional (Advanced)
- Use MetalLB if you want to manage LBs inside cluster.
- Add PersistentStorage via Hetzner Volumes.
- Autoscaler setup for worker nodes.
- Log/Monitoring: EFK, Prometheus stack.
Would you like a full GitHub-ready repo template with Terraform and Ansible wrappers for this setup?
Let me know also if you'd prefer OKD with IPI instead of UPI (IPI is not fully supported on Hetzner though).