Go to file
Simon Leiner a1ef590442
Add support for API servers on IPv6 addresses (#48)
* Remove duplicate file for deletion

* Add support for IPv6 clusters

To correctly escape IPv6 addresses when ports are used, they must be
wrapped in square brackets [1]. This patch adds support for that,
using Ansible's ipwrap filter [2].

[1]: https://datatracker.ietf.org/doc/html/rfc4038#section-5.1
[2]: http://docs.ansible.com/ansible/latest/collections/ansible/utils/docsite/filters_ipaddr.html#wrapping-ipv6-addresses-in-brackets

* Do not abort other molecule jobs on failure

* Fix cache keys for Vagrant boxes

* Molecule: Derive overrides.yml location from scenario dir

# Conflicts:
#	molecule/default/molecule.yml
#	molecule/ipv6/molecule.yml
2022-09-10 12:57:38 -05:00
.github Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
collections Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
example Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
inventory Test playbook using molecule (#67) 2022-09-03 10:36:28 -05:00
molecule Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
roles Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
.ansible-lint Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
.editorconfig add editorconfig and fix trailing whitespaces (#68) 2022-09-07 20:00:13 -05:00
.gitignore Test playbook using molecule (#67) 2022-09-03 10:36:28 -05:00
.yamllint initial commit 2022-03-27 10:05:37 -05:00
ansible.cfg initial commit 2022-03-27 10:05:37 -05:00
deploy.sh Readme updates (#4) 2022-03-27 11:18:45 -05:00
LICENSE initial commit 2022-03-27 10:05:37 -05:00
README.md Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
requirements.txt Add support for API servers on IPv6 addresses (#48) 2022-09-10 12:57:38 -05:00
reset.sh Readme updates (#4) 2022-03-27 11:18:45 -05:00
reset.yml initial commit 2022-03-27 10:05:37 -05:00
site.yml fix(ansible): Refactored ansible steps to now install metallb in post… (#58) 2022-08-28 14:25:09 -05:00

Automated build of HA k3s Cluster with kube-vip and MetalLB

Fully Automated K3S etcd High Availability Install

This playbook will build an HA Kubernetes cluster with k3s, kube-vip and MetalLB via ansible.

This is based on the work from this fork which is based on the work from k3s-io/k3s-ansible. It uses kube-vip to create a load balancer for control plane, and metal-lb for its service LoadBalancer.

If you want more context on how this works, see:

📄 Documentation (including example commands)

📺 Video

📖 k3s Ansible Playbook

Build a Kubernetes cluster 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

System requirements

  • Deployment environment must have Ansible 2.4.0+. If you need a quick primer on Ansible you can check out my docs and setting up Ansible. Furthermore, the netaddr package must be available to Ansible. If you have installed Ansible via apt, this is already taken care of. If you have installed Ansible via pip, make sure to install netaddr into the respective virtual environment.
  • server and agent nodes should have passwordless SSH access, if not you can supply arguments to provide credentials --ask-pass --ask-become-pass to each command.

🚀 Getting Started

🍴 Preparation

First create a new directory based on the sample directory within the inventory directory:

cp -R inventory/sample inventory/my-cluster

Second, 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
node

If 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.

☸️ Create Cluster

Start provisioning of the cluster using the following command:

ansible-playbook site.yml -i inventory/my-cluster/hosts.ini

After deployment control plane will be accessible via virtual ip-address which is defined in inventory/group_vars/all.yml as apiserver_endpoint

🔥 Remove k3s cluster

ansible-playbook reset.yml -i inventory/my-cluster/hosts.ini

You should also reboot these nodes due to the VIP not being destroyed

⚙️ Kube Config

To copy your kube config locally so that you can access your Kubernetes cluster run:

scp debian@master_ip:~/.kube/config ~/.kube/config

🔨 Testing your cluster

See the commands here.

Troubleshooting

Be sure to see this post on how to troubleshoot common problems

Testing the playbook using molecule

This playbook includes a molecule-based test setup. It is run automatically in CI, but you can also run the tests locally. This might be helpful for quick feedback in a few cases. You can find more information about it here.

Thanks 🤝

This repo is really standing on the shoulders of giants. To all those who have contributed.

Thanks to these repos for code and ideas: