---
title: kubeadm
description: "Build an on-premises Kubernetes cluster for OpenLM with the OpenLM kubeadm playbook (Ansible): load balancer, machines, DNS, network rules, storage, and node roles."
product: OpenLM Platform
---

To build an on-premises Kubernetes cluster for OpenLM, run the OpenLM kubeadm playbook. The playbook is an Ansible playbook that sets up the following:

- An **HAProxy load balancer** in front of the cluster: TLS termination for your host names, and the Kubernetes API on port 6443.
- **kubeadm** Kubernetes 1.32 with **Calico** networking and **metrics-server**.
- **Storage**: the local disk (`hostpath`) or replicated **Longhorn** storage, and optionally an extra **NFS** storage class.
- **Node roles**: every node gets a `role=<name>` label and taint, so that workloads run on the nodes meant for them.

The playbook builds a clean cluster. The OpenLM services are set up separately. Start small and grow the cluster by adding workers to the inventory.

The smallest setup is **two machines**: one Kubernetes node that is both the control plane and the worker (`examples/hosts-single-node.ini`), and the load balancer. The load balancer must be its own machine, because it listens on ports 80, 443, and 6443, the same ports as the node's ingress controller and API server. You can add workers later without rebuilding. See [Add machines later](#add-machines-later).

## How the cluster fits together

All traffic enters through the load balancer. It ends TLS with your certificate and passes web traffic to the ingress controller on the nodes, and Kubernetes API traffic to the control plane:

```text
 Users / kubectl
      |
      |  https://apps.example.com (443)      kubectl (6443)
      v
 +-------------------------------+
 | Load balancer (HAProxy)       |   TLS ends here (your certificate)
 |  80  -> redirect to 443       |
 |  443 -> ingress nodes :80     |
 |  6443 -> masters :6443 (TCP)  |
 +-------------------------------+
      |                    |
      v                    v
 +-----------+      +-------------------+
 | master(s) | <--> | workers           |   Calico pod network between all nodes
 | API, etcd |      | ingress (Traefik) |
 +-----------+      | applications      |
                    +-------------------+
```

The playbook runs in this order, one tag at a time:

```text
haproxy -> node_prep -> init_master -> join_worker -> node_affinity_taint -> ns -> storage_install
   LB       all nodes    first master    workers        labels + taints      namespaces   storage
```

## Before you start

Prepare the machines, the DNS records, the network rules, the certificate, and the control machine before you run the playbook.

### Machines

Size the machines with the following table:

| Machine | Minimum | Notes |
|---|---|---|
| Load balancer | 2 vCPU, 2 GB RAM, 20 GB disk | A separate machine, because it uses ports 80, 443, and 6443 itself. RHEL, AlmaLinux, or Rocky Linux 9, or Ubuntu 22.04 or 24.04. |
| Control plane node (`[masters]`) | 4 vCPU, 8 GB RAM, 50 GB disk | Ubuntu 22.04 or 24.04 |
| Worker | 4 vCPU, 16 GB RAM, 100 GB disk | Ubuntu 22.04 or 24.04 |
| Single-node setup (the control plane node runs workloads) | 8 vCPU, 32 GB RAM, 150 GB disk | The node's size must cover both roles. |

The table gives the minimum for the cluster itself. Size the workers for the OpenLM services you run with [Sizing](https://www.openlm.com/documentation/cloud/deployment-operations/on-premise/deployment-guide/kubernetes/before-you-start/sizing). A full OpenLM Platform on a single node comes close to the Kubernetes limit of 110 pods per node, so use workers for a full installation.

Every machine also needs the following:

- A static IP address, and a unique host name on every node.
- Internet access from every machine, directly or through a proxy set in the operating system, for OS packages, `pkgs.k8s.io`, Helm charts, and container registries.

The playbook turns swap off. Images and containers live in `/var/lib/containerd`. To use a separate data disk instead, see `node_data_disk_mount` in `roles/node_prep/defaults/main.yml`.

### DNS records

Create these DNS records, both pointing to the load balancer's IP address:

| DNS record | Example | Used for |
|---|---|---|
| `load_balancer_dns` | `k8s-lb.example.com` | The Kubernetes API, for the nodes and `kubectl` |
| Each name in `haproxy_hosts` | `apps.example.com` | Your applications |

### Network rules

Open the following connections:

| From | To | Ports |
|---|---|---|
| Users | Load balancer | TCP 80 and 443, plus 27017 and 30000 if MongoDB and Kafka passthrough is turned on |
| Administrators, nodes | Load balancer | TCP 6443 (Kubernetes API), and TCP 8081 for the HAProxy statistics page, administrators only |
| Load balancer | Control plane nodes | TCP 6443 |
| Load balancer | Ingress nodes | TCP 80, plus 27017 and 30000 if turned on |
| All cluster nodes | All cluster nodes | All traffic. At least TCP 6443, 2379-2380, 10250, and 179 (Calico BGP), and IP protocol 4 (IP-in-IP) or UDP 4789 (VXLAN). Longhorn also needs TCP 9500-9504 and iSCSI. |

The pod network `pod_network_cidr` (default `172.16.0.0/12`) and the service network `10.96.0.0/12` must not overlap your node or office networks. If they do, change `pod_network_cidr` before you install.

### TLS certificate

TLS ends on the load balancer. HAProxy needs **one PEM file** that holds the certificate, the intermediate chain, and the private key:

```bash
cat apps.example.com.crt intermediate.crt apps.example.com.key > cluster.pem
```

The certificate must be valid for every host name in `haproxy_hosts`. A wildcard certificate (`*.example.com`) is the simplest. Either put the file on the load balancer at `haproxy_cert_path` yourself, or set `haproxy_cert_src` to the local file, and the playbook copies it there with mode 0600. The playbook stops if the file is missing.

The Kubernetes API on port 6443 is passed through as TCP. Its certificates are created by kubeadm and are separate from yours.

### Control machine

Run the playbook from a machine with the following:

- Ansible 2.15 or newer, and Python 3.
- SSH access with a key to every machine, as a user that can use `sudo`.
- `git`, to download the playbook.

## Get the playbook

Download the playbook from the OpenLM Helm repository on GitHub, and install the Ansible collections it uses:

```bash
git clone --depth 1 --filter=blob:none --sparse https://github.com/OpenLM-Helm/helmcharts.git
cd helmcharts
git sparse-checkout set k8s_cluster_base
cd k8s_cluster_base
ansible-galaxy collection install -r requirements.yml
```

Run every command in the rest of this page from the `k8s_cluster_base` folder.

## Set up the inventory

Choose the example that matches your layout:

| Example | Layout |
|---|---|
| `examples/hosts-single-node.ini` | One machine runs the control plane and the workloads. |
| `examples/hosts-master-workers.ini` | A dedicated control plane node and workers |
| `examples/hosts-master-infra-workers.ini` | A control plane node, an infrastructure node (ingress, databases, storage), and application workers |

Copy it, together with the settings file:

```bash
mkdir -p inventory/group_vars
cp examples/hosts-single-node.ini inventory/hosts.ini
cp examples/group_vars-all.yml inventory/group_vars/all.yml
```

`ansible.cfg` already points at `inventory/hosts.ini`. The inventory has three groups:

| Group | Contains | Settings per host |
|---|---|---|
| `[masters]` | The control plane nodes. The first one initializes the cluster. | `ansible_host`, `node_label`, `node_taint` |
| `[workers]` | The nodes that run workloads | `ansible_host`, `node_label`, `node_taint`, `node_data_disk_mount` (optional) |
| `[lb]` | The HAProxy machine | `ansible_host` |

Follow these rules when you fill in the groups:

- The inventory names of control plane nodes and workers must be the node host names (the output of `hostname`). Labels and taints are applied by that name.
- `node_label` and `node_taint` set the node role, for example `role=main` or `role=infrastructure`. Nodes without them get `default_label` and `default_taints`, which are `main`.
- To let a control plane node run workloads, list it in `[masters]` and in `[workers]`. It then gets its role label and taint like a worker, and the control plane taint is removed. A control plane node that's only in `[masters]` keeps the control plane taint and runs no workloads.

## Set the cluster settings

Edit `inventory/group_vars/all.yml`. Every setting is described in the file and in `roles/<role>/defaults/main.yml`. The following settings are required:

| Setting | Example | Meaning |
|---|---|---|
| `load_balancer_dns` | `k8s-lb.example.com` | The DNS name of the load balancer, the cluster's API endpoint |
| `haproxy_hosts` | `[apps.example.com]` | The public host names of your applications |
| `haproxy_cert_path` | `/etc/haproxy/certs/cluster.pem` | The PEM file on the load balancer |
| `haproxy_stats_pass` | (secret) | The password of the statistics page. Or set `haproxy_stats_enabled: false`. |

Also review the following settings:

- `storage_type`: `hostpath` for one node, `longhorn` for several. See [Storage](#storage).
- `haproxy_ingress_nodes`: the nodes where the ingress controller runs. Empty means every worker.
- `haproxy_enable_mongo` and `haproxy_enable_kafka`: TCP passthrough on the load balancer to the ingress nodes, for MongoDB on port 27017 and Kafka on port 30000. The ingress controller needs matching TCP entry points.
- `k8s_namespaces_extra`: your own namespaces. See [Namespaces](#namespaces).

Keep the statistics password out of plain text, for example with Ansible Vault:

```bash
ansible-vault encrypt_string 'the-password' --name haproxy_stats_pass >> inventory/group_vars/all.yml
```

Then add `--ask-vault-pass` to the commands in [Build the cluster](#build-the-cluster).

## Build the cluster

Run the tags one at a time, in this order, and check each step before the next. `-K` asks for the `sudo` password. Leave it out if your user has passwordless `sudo`.

```bash
ansible-playbook deploy-pbk.yml -K --tags haproxy              # load balancer + TLS
ansible-playbook deploy-pbk.yml -K --tags node_prep            # packages, containerd, kernel settings, kubeadm
ansible-playbook deploy-pbk.yml -K --tags init_master          # kubeadm init on the first master, Calico
ansible-playbook deploy-pbk.yml -K --tags join_master          # only with more than one master
ansible-playbook deploy-pbk.yml -K --tags join_worker          # join the workers
ansible-playbook deploy-pbk.yml -K --tags node_affinity_taint  # role labels and taints
ansible-playbook deploy-pbk.yml -K --tags metrics_server       # kubectl top
ansible-playbook deploy-pbk.yml -K --tags ns
ansible-playbook deploy-pbk.yml -K --tags storage_install
```

On a single node, `calico-typha` stays `Pending` and the node's Calico pod isn't ready after `init_master`, because the only node still has the control plane taint. That's expected. `node_affinity_taint` removes the taint, because the node is in `[workers]`, and Calico becomes ready. Run it before `metrics_server`.

You can run every step again safely: finished work, such as an initialized control plane, joined nodes, or installed charts, is detected and skipped.

`node_prep` adds kernel arguments (`node_kernel_args`) to GRUB, and they take effect at the next restart. Current Ubuntu releases have the needed cgroups turned on already, so you don't need to restart to continue.

### Check the cluster

On the first control plane node, run these commands:

```bash
sudo kubectl --kubeconfig /etc/kubernetes/admin.conf get nodes -o wide
sudo kubectl --kubeconfig /etc/kubernetes/admin.conf get pods -A
```

All nodes must be `Ready` and all pods `Running`. To use `kubectl` from your own machine, copy `/etc/kubernetes/admin.conf` from the first control plane node to `~/.kube/config`. It already points at `https://<load_balancer_dns>:6443`. It's a full administrator credential, so keep it safe.

The load balancer's statistics page is at `http://<load balancer>:8081/stats`. The ingress back end shows `DOWN` until an ingress controller runs on the ingress nodes.

### Namespaces

The `ns` tag creates the namespaces that the OpenLM platform is deployed into:

| Namespace | For |
|---|---|
| `openlm` | OpenLM applications |
| `openlm-infrastructure` | Shared infrastructure |
| `openlm-telemetry` | Monitoring: Grafana, Prometheus, Loki, Tempo, OpenTelemetry |
| `redis` | Redis |
| `traefik` | The ingress controller |
| `headlamp` | The Kubernetes web UI |

Keep these names. The OpenLM services and the API gateway reach each other through in-cluster service names (`<service>.<namespace>.svc`), so a different namespace breaks those calls. To add your own namespaces, use `k8s_namespaces_extra`.

### Run workloads

Every node that runs workloads is tainted `role=<name>:NoSchedule`. A pod runs only where it tolerates the taint, so give your deployments a toleration and a node selector for their role:

```yaml
nodeSelector:
  role: main
tolerations:
  - key: role
    operator: Equal
    value: main
    effect: NoSchedule
```

Pods without a `role` toleration stay `Pending`. Calico, CoreDNS, metrics-server, and Longhorn already tolerate every `role` taint.

The ingress controller, for example Traefik, must run with `hostNetwork` on the nodes in `haproxy_ingress_nodes` and listen on port 80. The load balancer sends all HTTPS traffic for `haproxy_hosts` there, already decrypted, with `X-Forwarded-Proto: https`.

## Add machines later

To grow the cluster, add machines to the inventory and run the tags for them.

**Add a worker:** Add it to `[workers]` with its `node_label` and `node_taint`, then run:

```bash
ansible-playbook deploy-pbk.yml -K --tags node_prep,join_worker,node_affinity_taint
```

With Longhorn, also run `--tags longhorn_prereqs`, plus `longhorn_storage_nodes` if you restrict where data lives.

**Go from a single node to a dedicated control plane node:** Once enough workers run the workloads, follow these steps:

1. Drain the control plane node: `kubectl drain <node> --ignore-daemonsets --delete-emptydir-data`.
2. Remove it from `[workers]` and run `--tags node_affinity_taint` again. The control plane taint is put back before the role taint is removed.
3. Run `kubectl uncordon <node>`.

Data in `hostpath` volumes stays on that node's disk, and you move it yourself.

**Add control plane nodes:** Add them to `[masters]` and run `--tags node_prep,join_master`, then `--tags haproxy` so that the load balancer sends API traffic to all of them. Use one or three control plane nodes: an odd number.

Run `--tags haproxy` again whenever you change `haproxy_hosts`, `haproxy_ingress_nodes`, or the control plane nodes.

## Storage

Choose the storage type with `storage_type`. The following table compares the two types:

| `storage_type` | Storage class | Data lives on | Use it for |
|---|---|---|---|
| `hostpath` (default) | `hostpath` | The local disk of the node where the pod first ran. Lost if that node is lost. | A single node, test setups |
| `longhorn` | `longhorn` | `longhorn_replica_count` copies on different nodes | Several nodes |

`nfs_storageclass_enabled: true` adds an `nfs` storage class on an NFS export you already have. Each volume becomes a folder on the share. Use it for files, not for databases: MongoDB, Kafka, and Prometheus need block storage. The export must be reachable from every node with `rw,sync,no_subtree_check,no_root_squash`.

The Longhorn UI isn't exposed. To open it, forward its port and go to `http://localhost:8080`:

```bash
kubectl -n longhorn-system port-forward svc/longhorn-frontend 8080:80
```

To back up Longhorn volumes to NFS, set `longhorn_backup_target`.

## Renew the certificate

When the certificate is renewed, replace the file and reload HAProxy with `systemctl reload haproxy`. Or run `--tags haproxy` again with `haproxy_cert_src`.

## Tags

Each tag runs one part of the playbook:

| Tag | Does |
|---|---|
| `haproxy` | Installs and configures HAProxy on `[lb]`, and checks the certificate |
| `node_prep` | All node preparation (sub-tags `packages`, `data_disk`, `containerd`, `cgroup`, `swap`, `k8s_install`) |
| `init_master` | `kubeadm init` on the first control plane node, Calico, and role tolerations for Calico and CoreDNS |
| `join_master` / `join_worker` | Joins more control plane nodes or workers |
| `metrics_server` | metrics-server (`kubectl top`) |
| `node_affinity_taint` | Role labels and taints (sub-tags `node_label`, `node_taint`) |
| `ns` | Creates the OpenLM namespaces plus `k8s_namespaces_extra` |
| `storage_install` | Storage (sub-tags `hostpath`, `longhorn`, `longhorn_prereqs`, `nfs_storageclass`) |

To limit node tasks to chosen nodes, pass `-e '{"only_nodes":["k8s-w-3"]}'`. `--limit` doesn't work here, because the roles run once and loop over the inventory groups.

## Troubleshooting

Find the symptom in the following table:

| Symptom | Check |
|---|---|
| `haproxy` stops: certificate not found | `haproxy_cert_path` on the load balancer, or set `haproxy_cert_src` |
| `init_master` stops responding, or the API can't be reached | The DNS record of `load_balancer_dns`, port 6443 open from the load balancer to the control plane nodes, and that `haproxy` ran first |
| A node is `NotReady` | `kubectl -n calico-system get pods -o wide`, and that traffic between nodes is allowed. See [Network rules](#network-rules). |
| Pods stay `Pending` | `kubectl describe pod`: usually a missing `role` toleration, or no storage class for the volume claim |
| The ingress back end is `DOWN` on the statistics page | The ingress controller isn't running with `hostNetwork` on `haproxy_ingress_nodes`. |
| Kubernetes upgrade | After `kubeadm upgrade`, run `--tags init_master` again: it puts the CoreDNS tolerations back. Change `kubernetes_repo_url` for each minor version. |

To move the images of an existing node to a data disk, drain the node first, then run `sudo bash scripts/move-containerd-to-data-disk.sh <mount point>` on it. Once the node is healthy, run the script again with `--cleanup`.
