2023-11-08 19:38:48 +01:00
|
|
|
# Under Construction :construction:
|
|
|
|
|
2020-03-04 10:47:40 +01:00
|
|
|
# Build a Kubernetes cluster using k3s via Ansible
|
2019-04-26 21:10:27 +02:00
|
|
|
|
2020-03-04 10:47:40 +01:00
|
|
|
Author: <https://github.com/itwars>
|
2019-05-18 19:58:25 +02:00
|
|
|
|
2019-04-26 21:10:27 +02:00
|
|
|
## K3s Ansible Playbook
|
|
|
|
|
|
|
|
Build a Kubernetes cluster using Ansible with k3s. The goal is easily install a Kubernetes cluster on machines running:
|
|
|
|
|
2020-03-04 10:47:40 +01:00
|
|
|
- [X] Debian
|
2020-05-22 18:01:03 +02:00
|
|
|
- [X] Ubuntu
|
2020-03-04 10:47:40 +01:00
|
|
|
- [X] CentOS
|
2023-11-08 19:31:51 +01:00
|
|
|
- [X] ArchLinux
|
2019-04-26 21:10:27 +02:00
|
|
|
|
|
|
|
on processor architecture:
|
|
|
|
|
|
|
|
- [X] x64
|
|
|
|
- [X] arm64
|
|
|
|
- [X] armhf
|
|
|
|
|
2020-03-04 10:47:40 +01:00
|
|
|
## System requirements
|
2019-04-26 21:10:27 +02:00
|
|
|
|
|
|
|
Deployment environment must have Ansible 2.4.0+
|
|
|
|
Master and nodes must have passwordless SSH access
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
2023-01-30 19:46:09 +01:00
|
|
|
First copy the sample inventory to `inventory.yml`.
|
2020-06-06 10:52:12 +02:00
|
|
|
|
|
|
|
```bash
|
2023-01-30 19:46:09 +01:00
|
|
|
cp inventory-sample.yml inventory.yml
|
2020-06-06 10:52:12 +02:00
|
|
|
```
|
|
|
|
|
2023-01-30 19:46:09 +01:00
|
|
|
Second edit the inventory file to match your cluster setup. For example:
|
2020-03-04 10:47:40 +01:00
|
|
|
```bash
|
2023-01-30 19:46:09 +01:00
|
|
|
k3s_cluster:
|
|
|
|
children:
|
|
|
|
server:
|
|
|
|
hosts:
|
|
|
|
192.16.35.11
|
|
|
|
agent:
|
|
|
|
hosts:
|
|
|
|
192.16.35.12
|
|
|
|
192.16.35.13
|
|
|
|
```
|
2019-04-26 21:10:27 +02:00
|
|
|
|
2023-01-30 19:46:09 +01:00
|
|
|
If needed, you can also edit `vars` section at the bottom to match your environment.
|
2019-04-26 21:10:27 +02:00
|
|
|
|
2023-01-30 19:46:09 +01:00
|
|
|
If multiple hosts are in the server group the playbook will automatically setup k3s in HA mode with embedded etcd.
|
|
|
|
An odd number of server nodes is recommended (3,5,7). Read the offical documentation below for more information and options.
|
|
|
|
https://rancher.com/docs/k3s/latest/en/installation/ha-embedded/
|
|
|
|
Using a loadbalancer or VIP as the API endpoint is preferred but not covered here.
|
2019-04-26 21:10:27 +02:00
|
|
|
|
2020-06-06 10:52:12 +02:00
|
|
|
|
2019-04-26 21:10:27 +02:00
|
|
|
Start provisioning of the cluster using the following command:
|
|
|
|
|
2020-03-04 10:47:40 +01:00
|
|
|
```bash
|
2023-01-30 19:46:09 +01:00
|
|
|
ansible-playbook playbook/site.yml -i inventory.yml
|
2019-04-26 21:10:27 +02:00
|
|
|
```
|
|
|
|
|
2019-05-18 19:58:25 +02:00
|
|
|
## Kubeconfig
|
|
|
|
|
2023-02-02 18:57:02 +01:00
|
|
|
To confirm access to your **Kubernetes** cluster use the following:
|
2020-03-04 10:47:40 +01:00
|
|
|
|
|
|
|
```bash
|
2023-02-02 18:57:02 +01:00
|
|
|
kubectl get nodes
|
2020-03-04 10:47:40 +01:00
|
|
|
```
|