To easily configure a self-hosted Kubernetes cluster we can use Ansible.
Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs. It uses no agents and no additional custom security infrastructure, so it's easy to deploy - and most importantly, it uses a very simple language (YAML, in the form of Ansible Playbooks) that allow you to describe your automation jobs in a way that approaches plain English.
-
Ansible does NOT run on Windows, if needed WSL can be used.
-
Instructions on how to install ansible are available here.
-
An authorized SSH user and key must be provided.
In order to provision the VMs we need some preparation.
-
Install Ansible (refer to the respective documentations)
-
Populate the
hosts.ini
fileVagrant dev setup
Update the number of
workers
in thehosts.ini
file, according to theWORKER_NODES
variable in theVagrantfile
.Workers hostnames follow the syntax worker-node0N being N the node number, there should be nodes from 1 to N.
Real Environment
Assuming that two or more Debian 11 hosts are available.
Populate
master
with only one IP/FQHS corresponding to a host node and as manyworkers
as you'd like.
-
SSH Config
- Add an authorized private key to your SSH agent.
- Instructions for Windows/WSL can be found here.
- Edit the
k3s.yaml
file indicating the ssh user by replacing the value in theremote_user
variable, this is not required if using the Vagrant dev environment.
-
Install the required ansible packages by running the following command in this directory.
ansible-galaxy install -r requirements.yml
After preparing the environment is just a matter of running the following command in the ansible directory and waiting a couple of minutes:
ansible-playbook -i hosts.ini k3s.yaml
The result will be a configured Kubernetes Cluster. In order to access the cluster the credentials file is available in the same folder with the name credentials.yaml
, before accessing the cluster edit the server address inside the file to that of the master node.