Skip to main content

kubeadm

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.

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:

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:

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:

MachineMinimumNotes
Load balancer2 vCPU, 2 GB RAM, 20 GB diskA 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 diskUbuntu 22.04 or 24.04
Worker4 vCPU, 16 GB RAM, 100 GB diskUbuntu 22.04 or 24.04
Single-node setup (the control plane node runs workloads)8 vCPU, 32 GB RAM, 150 GB diskThe 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. 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 recordExampleUsed for
load_balancer_dnsk8s-lb.example.comThe Kubernetes API, for the nodes and kubectl
Each name in haproxy_hostsapps.example.comYour applications

Network rules​

Open the following connections:

FromToPorts
UsersLoad balancerTCP 80 and 443, plus 27017 and 30000 if MongoDB and Kafka passthrough is turned on
Administrators, nodesLoad balancerTCP 6443 (Kubernetes API), and TCP 8081 for the HAProxy statistics page, administrators only
Load balancerControl plane nodesTCP 6443
Load balancerIngress nodesTCP 80, plus 27017 and 30000 if turned on
All cluster nodesAll cluster nodesAll 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:

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:

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:

ExampleLayout
examples/hosts-single-node.iniOne machine runs the control plane and the workloads.
examples/hosts-master-workers.iniA dedicated control plane node and workers
examples/hosts-master-infra-workers.iniA control plane node, an infrastructure node (ingress, databases, storage), and application workers

Copy it, together with the settings file:

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:

GroupContainsSettings per host
[masters]The control plane nodes. The first one initializes the cluster.ansible_host, node_label, node_taint
[workers]The nodes that run workloadsansible_host, node_label, node_taint, node_data_disk_mount (optional)
[lb]The HAProxy machineansible_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:

SettingExampleMeaning
load_balancer_dnsk8s-lb.example.comThe 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.pemThe 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.
  • 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.

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

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​

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.

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:

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:

NamespaceFor
openlmOpenLM applications
openlm-infrastructureShared infrastructure
openlm-telemetryMonitoring: Grafana, Prometheus, Loki, Tempo, OpenTelemetry
redisRedis
traefikThe ingress controller
headlampThe 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:

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:

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_typeStorage classData lives onUse it for
hostpath (default)hostpathThe local disk of the node where the pod first ran. Lost if that node is lost.A single node, test setups
longhornlonghornlonghorn_replica_count copies on different nodesSeveral 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:

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:

TagDoes
haproxyInstalls and configures HAProxy on [lb], and checks the certificate
node_prepAll node preparation (sub-tags packages, data_disk, containerd, cgroup, swap, k8s_install)
init_masterkubeadm init on the first control plane node, Calico, and role tolerations for Calico and CoreDNS
join_master / join_workerJoins more control plane nodes or workers
metrics_servermetrics-server (kubectl top)
node_affinity_taintRole labels and taints (sub-tags node_label, node_taint)
nsCreates the OpenLM namespaces plus k8s_namespaces_extra
storage_installStorage (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:

SymptomCheck
haproxy stops: certificate not foundhaproxy_cert_path on the load balancer, or set haproxy_cert_src
init_master stops responding, or the API can't be reachedThe 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 NotReadykubectl -n calico-system get pods -o wide, and that traffic between nodes is allowed. See Network rules.
Pods stay Pendingkubectl describe pod: usually a missing role toleration, or no storage class for the volume claim
The ingress back end is DOWN on the statistics pageThe ingress controller isn't running with hostNetwork on haproxy_ingress_nodes.
Kubernetes upgradeAfter 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.

The documentation team might draft this page using a large language model. A technical writer reviews every page and verifies it against the product before publishing it. A human makes the final decision.