Ansible playbook for kubeadm-based Kubernetes cluster installation on Linux
This Ansible playbook automates the installation and configuration of a Kubernetes cluster on Linux, supporting both single control plane and HA control plane setups, using the latest stable Kubernetes release.
While Kubespray provides extensive features and customization options, this playbook remains lightweight and simple, making it an ideal choice for quickly setting up a development or testing Kubernetes environment on Linux.
Suitable Environment: Development & Testing
System Requirements: Minimum 2 GB RAM & 2 vCPU
Supported Platforms: Baremetal, Virtual Machines, Cloud Instances
- RedHat-based ( Fedora, RHEL, Rocky Linux, Almalinux, Oracle Linux )
- Debian-based ( Debian, Ubuntu )
- SUSE-based ( OpenSUSE, SLES )
- Please install Ansible on the machine where you plan to run the playbook if you haven’t done so already.
- Prepare the cluster nodes by installing any of the above mentioned supported Linux distributions, even with a minimal installation.
- Please ensure that you have DNS set up that resolves all the involved hosts, or update the host files on all hosts with the necessary entries for each involved host.
- Create a common Linux user on all cluster nodes, which will be used for the cluster installation.
- Enable passwordless SSH authentication from the Ansible host to all cluster nodes using the common user created earlier.
- Ensure the common user has passwordless sudo privileges on all cluster nodes.
- For HA cluster setups, ensure that the control plane endpoint is configured via a load balancer such as NGINX, HAProxy, or any load balancer of your choice.
The main playbook installs and configures the latest stable versions of the following required components.
- Container orchestrator: kubernetes
- Container runtime: containerd
- Low-level container runtime: runc ( dependency for containerd )
- CNI plugin: calico
- csi-driver-nfs
- csi-driver-smb
- MetalLB LoadBalancer
Step 1) Copy and execute the below command snippet to extract the tarball for the most recent stable release of this Ansible project.
curl -sSL https://github.com/Muthukumar-Subramaniam/install-k8s-on-linux/releases/latest/download/inst-k8s-ansible.tar.gz | tar -xzvf - && cd inst-k8s-ansible
Use a single control plane node for a single control plane setup. For HA cluster setups, ensure a minimum of 3 control plane nodes, and always use an odd number of nodes.


-
Update the file**
control-plane-endpoint
with the endpoint behind the load balancer that has all the control planes in the backend pool. -
Port configuration:
If only<FQDN of control-plane-endpoint>
is provided, the default port6443
will be used.
Alternatively, provide a specific port as<FQDN of control-plane-endpoint>:<port-number>
.( Or )


- Only private IP addresses, as defined in RFC 1918 are allowed.
- The deployment is configured to accept CIDR prefixes exclusively within the /16 to /28 range.
- Ensure that the selected CIDR prefix does not conflict with any existing networks in your infrastructure.
- Choose a CIDR prefix that provides sufficient address space for your cluster.
./setup.py

./inst-k8s-ansible.yaml
Expected Outcome:

./optional-k8s-csi-nfs-driver.yaml
Expected Outcome:

./optional-k8s-csi-smb-driver.yaml
Expected Outcome:

Note: Please make sure to change the address pool range in the playbook as per your environment and requirement.

./optional-install-metallb.yaml
Expected Outcome:

That's all for now! Your trust and engagement means a lot, and we hope you find the playbook useful.
- This playbook is a useful resource for experimenting with Kubernetes and can be customized to meet your specific requirements.
- The playbook utilizes the GitHub API to fetch the current stable versions of all required software components.
- Compatible with a wide range of Linux distributions.
- Your feedback and contributions are invaluable to the success of this project.
- Please report any bugs, suggest new features, or contribute directly to the codebase.