Author: https://github.com/itwars
Build a Kubernetes cluster using Ansible with k3s. The goal is easily install a Kubernetes cluster on machines running:
- Debian
- Ubuntu
- CentOS
on processor architecture:
- x64
- arm64
- armhf
Deployment environment must have Ansible 2.4.0+ Master and nodes must have passwordless SSH access
| Variable | Example | Description |
|---|---|---|
| ansible_user | ubuntu | user to connect via ssh to to master |
| ansible_ssh_private_key_file | ./secrets/id_rsa | ssh private key file |
| k3s_version | 1.25.9+k3s1 | k3s version from https://github.com/k3s-io/k3s/releases |
| systemd_dir | /etc/systemd/system | path to systemd |
| master_address | 192.168.1.2 | master node address or FQDN (used only for single node) |
Edit inventory/single_node/group_vars/all.yml to match your environment.
ansible-playbook site.yml -i inventory/single_node/hosts.ini --extra-vars "master_address=192.168.1.2"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.16.35.12
[node]
192.16.35.[10:11]
[k3s_cluster:children]
master
nodeIf 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.iniRun the following playbook against the original inventory used to deploy the nodes, ex.
ansible-playbook reset.yml -i inventory/my-cluster/hosts.inior
ansible-playbook reset.yml -i inventory/single_node/hosts.ini --extra-vars "master_address=192.168.1.2"To get access to your Kubernetes cluster just
scp ubuntu@master_ip:~/.kube/config ~/.kube/config