This playbook will build a HA Kubernetes cluster with k3s, kube-vip, MetalLB, and Cilium via ansible.
Cilium installation is done via helm to ensure easy upgrades and future customization of values
Build a Kubernetes cluster with a built-in service mesh using Ansible with k3s. The goal is easily install a HA Kubernetes cluster on machines running:
- Debian
- Ubuntu
- CentOS
on processor architecture:
- x64
- arm64
- armhf
- Deployment environment must have Ansible 2.4.0+.
serverandagentnodes should have passwordless SSH access, if not you can supply arguments to provide credentials--ask-pass --ask-become-passto each command.
First create a new directory based on the sample directory within the inventory directory:
cp -R inventory/sample inventory/my-clusterSecond, edit inventory/my-cluster/hosts.ini to match the system information gathered above
For example:
[master]
192.168.30.38
192.168.30.39
192.168.30.40
[node]
192.168.30.41
192.168.30.42
[k3s_cluster:children]
master
nodeIf multiple hosts are in the master group, the playbook will automatically set up k3s in HA mode with etcd.
This requires at least k3s version 1.19.1 however the version is configurable by using the k3s_version variable.
If needed, you can also edit inventory/my-cluster/group_vars/all.yml to match your environment.
Start provisioning of the cluster using the following command:
ansible-playbook site.yml -i inventory/my-cluster/hosts.iniAfter deployment control plane will be accessible via virtual ip-address which is defined in inventory/group_vars/all.yml as apiserver_endpoint
ansible-playbook reset.yml -i inventory/my-cluster/hosts.iniYou should also reboot these nodes due to the VIP not being destroyed
To copy your kube config locally so that you can access your Kubernetes cluster run:
scp debian@master_ip:~/.kube/config ~/.kube/configThanks to these repos for code and ideas: