Install a Baremetal High-Availability Kubernetes Cluster using Ansible and kubeadm. This playbook automates the setup process and ensures a robust, production-ready environment with:
- Containerd as the container runtime.
- Cilium as the CNI (Container Network Interface).
- HAProxy & Keepalived for control plane load balancing and failover.
📌 Note: A Jumphost is used in the playbook to connect to all nodes.
The cluster consists of the following components:
- Load balancers using HAProxy for API server traffic.
- Keepalived ensures high availability via a virtual IP (VIP).
- Control plane nodes running
kube-apiserver
,kube-controller-manager
,kube-scheduler
, andetcd
.
- Nodes responsible for running application workloads.
[k8s:children]
masters
workers
[nodes:children]
k8s
haproxy
[haproxy]
web01 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
web02 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
[masters]
master1 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
master2 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
master3 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
[workers]
worker1 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
worker2 ansible_host=<ip> ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=<path_to_private_key>
[kvip]
web01
[all:vars]
ansible_ssh_common_args='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ProxyCommand="ssh -i <path_to_jumphost_key> -q -W %h:%p ubuntu@<jumphost_floating_ip>"'
- Applies basic system configurations to all nodes.
- Installs dependencies required for Kubernetes components.
- Installs and configures containerd as the container runtime.
- Installs
kubeadm
,kubelet
, andkubectl
.
- HAProxy for API server load balancing.
- Keepalived for a virtual IP, ensuring control plane high availability.
- The first master node initializes the cluster.
- Worker nodes join the cluster using
kubeadm
.
- The remaining master nodes join to create a HA control plane.
- Configures terminal access and other essential settings.
🔸 Templating for HAProxy & Keepalived 🔸
- HAProxy and Keepalived configuration files should be dynamically generated using Jinja templates.
🔸 Reorganization of the Playbook 🔸
- The playbook structure should be improved for better readability and maintainability.
git clone <repo_url>
cd <repo_directory>
Modify inventory.ini
to reflect your infrastructure details.
ansible-playbook -i inventory.ini site.yaml
✅ Implement HAProxy & Keepalived Jinja templates.
Suggestions are wellcomed! Feel free to open issues or submit pull requests to improve this playbook. 🚀