Commit df67c61b authored by Nicholas Malcolm's avatar Nicholas Malcolm Committed by Derek Nola
Browse files

Add HA option, change to yaml inventory, cleanup



- HA option for multiple server nodes using embedded etcd
- Switch to yaml inventory file for easier editing and combining vars
- Update to full ansible module names
- Change master/node names to server/agent
- Cleanup small linting errors
- Add reboot playbook which staggers reboot to keep HA cluster up
- Move playbooks to playbook directory

Signed-off-by: default avatarDerek Nola <derek.nola@suse.com>
parent 1031ea3c
Loading
Loading
Loading
Loading
+20 −15
Original line number Diff line number Diff line
@@ -23,32 +23,37 @@ Master and nodes must have passwordless SSH access

## Usage

First create a new directory based on the `sample` directory within the `inventory` directory:
First copy the sample inventory to `inventory.yml`.

```bash
cp -R inventory/sample inventory/my-cluster
cp inventory-sample.yml inventory.yml
```

Second, edit `inventory/my-cluster/hosts.ini` to match the system information gathered above. For example:

Second edit the inventory file to match your cluster setup. For example:
```bash
[master]
k3s_cluster:
  children:
    server:
      hosts:
        192.16.35.11
    agent:
      hosts:
        192.16.35.12
        192.16.35.13
```

[node]
192.16.35.[10:11]
If needed, you can also edit `vars` section at the bottom to match your environment.

[k3s_cluster:children]
master
node
```
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.

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:

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

## Kubeconfig
@@ -56,5 +61,5 @@ ansible-playbook site.yml -i inventory/my-cluster/hosts.ini
To get access to your **Kubernetes** cluster just

```bash
scp debian@master_ip:~/.kube/config ~/.kube/config
scp debian@server_ip:~/.kube/config ~/.kube/config
```
+1 −1
Original line number Diff line number Diff line
[defaults]
nocows = True
roles_path = ./roles
inventory  = ./hosts.ini
inventory  = ./inventory.yml

remote_tmp = $HOME/.ansible/tmp
local_tmp  = $HOME/.ansible/tmp

inventory-sample.yml

0 → 100644
+21 −0
Original line number Diff line number Diff line
---
k3s_cluster:
  children:
    server:
      hosts:
        192.16.35.11
    agent:
      hosts:
        192.16.35.12
        192.16.35.13

  vars:
    ansible_port: 22
    ansible_user: debian
    k3s_version: v1.25.5+k3s2
    systemd_dir: /etc/systemd/system
    api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
    api_port: 6443
    extra_server_args: ""
    extra_server_init_args: ""
    extra_agent_args: ""

inventory/.gitignore

deleted100644 → 0
+0 −3
Original line number Diff line number Diff line
*
!.gitignore
!sample/
 No newline at end of file
+0 −7
Original line number Diff line number Diff line
---
k3s_version: v1.22.3+k3s1
ansible_user: debian
systemd_dir: /etc/systemd/system
master_ip: "{{ hostvars[groups['master'][0]]['ansible_host'] | default(groups['master'][0]) }}"
extra_server_args: ""
extra_agent_args: ""
Loading