mirror of
https://github.com/PyratLabs/ansible-role-k3s
synced 2025-01-06 09:40:19 +01:00
Added workflow for Database backed and DQLite HA
This commit is contained in:
parent
7e7cf2b97d
commit
3a1c7e7b35
6 changed files with 64 additions and 11 deletions
|
@ -37,7 +37,12 @@ env:
|
|||
|
||||
# Test multiple masters in control plane with PostgreSQL
|
||||
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
|
||||
MOLECULE_SCENATIO: highavailability
|
||||
MOLECULE_SCENARIO: highavailability
|
||||
|
||||
# Test multiple masters in control plane with DQLite
|
||||
- MOLECULE_DISTRO: geerlingguy/docker-centos8-ansible:latest
|
||||
MOLECULE_SCENARIO: highavailability
|
||||
MOLECULE_PLAYBOOK: playbook-dqlite.yml
|
||||
|
||||
install:
|
||||
# Install test dependencies.
|
||||
|
|
|
@ -43,7 +43,7 @@ platforms:
|
|||
networks:
|
||||
- name: k3snet
|
||||
- name: loadbalancer
|
||||
image: nginx:1.16-alpine
|
||||
image: nginx:1.17-alpine
|
||||
pre_build_image: true
|
||||
ports:
|
||||
- "6443:6443"
|
||||
|
|
|
@ -1,20 +1,34 @@
|
|||
events { }
|
||||
worker_processes 4;
|
||||
worker_rlimit_nofile 40000;
|
||||
|
||||
http {
|
||||
events {
|
||||
worker_connections 8192;
|
||||
}
|
||||
|
||||
stream {
|
||||
# Set up our upstream of control (master) nodes. The default load balancing
|
||||
# algorithm for nginx is to round-robin. Perfect!
|
||||
upstream control_plane {
|
||||
server node2:6443;
|
||||
server node3:6443;
|
||||
server node2:6443 max_fails=3 fail_timeout=5s;
|
||||
server node3:6443 max_fails=3 fail_timeout=5s;
|
||||
}
|
||||
|
||||
upstream control_plane_443 {
|
||||
server node2:443 max_fails=3 fail_timeout=5s;
|
||||
server node3:443 max_fails=3 fail_timeout=5s;
|
||||
}
|
||||
|
||||
# Listen on port 6443, this is our default control plane port, then pass
|
||||
# all traffic to one of the control (master) nodes.
|
||||
server {
|
||||
listen 6443;
|
||||
proxy_pass control_plane;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://control_plane;
|
||||
}
|
||||
# Listen on port 443, this is our default ssl port, then pass
|
||||
# all traffic to one of the control (master) nodes.
|
||||
server {
|
||||
listen 443;
|
||||
proxy_pass control_plane_443;
|
||||
}
|
||||
}
|
||||
|
|
15
molecule/highavailability/playbook-dqlite.yml
Normal file
15
molecule/highavailability/playbook-dqlite.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
- name: Converge
|
||||
hosts: node*
|
||||
become: true
|
||||
vars:
|
||||
molecule_is_test: true
|
||||
k3s_dqlite_datastore: true
|
||||
k3s_use_experimental: true
|
||||
pre_tasks:
|
||||
- name: Set each node to be a control node
|
||||
set_fact:
|
||||
k3s_control_node: true
|
||||
when: inventory_hostname in ['node2', 'node3']
|
||||
roles:
|
||||
- role: xanmanning.k3s
|
|
@ -8,12 +8,14 @@
|
|||
@@@
|
||||
{{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}
|
||||
@@@
|
||||
{{ hostvars[item].k3s_control_node }}
|
||||
C_{{ hostvars[item].k3s_control_node }}
|
||||
@@@
|
||||
P_{{ hostvars[item].k3s_primary_control_node | default(False) }}
|
||||
create: true
|
||||
loop: "{{ play_hosts }}"
|
||||
|
||||
- name: Lookup control node from file
|
||||
command: "grep 'True' /tmp/inventory.txt"
|
||||
command: "grep '{{ 'P_True' if (k3s_controller_count | length > 1) else 'C_True' }}' /tmp/inventory.txt"
|
||||
changed_when: false
|
||||
register: k3s_control_delegate_raw
|
||||
|
||||
|
|
|
@ -56,6 +56,23 @@ ExecStart={{ k3s_install_dir }}/k3s
|
|||
{% endif %}
|
||||
{% if k3s_datastore_endpoint is defined and k3s_datastore_endpoint %}
|
||||
--datastore-endpoint "{{ k3s_datastore_endpoint }}"
|
||||
{% if k3s_datastore_cafile is defined and k3s_datastore_cafile %}
|
||||
--datastore-cafile {{ k3s_datastore_cafile }}
|
||||
{% endif %}
|
||||
{% if k3s_datastore_certfile is defined and k3s_datastore_certfile %}
|
||||
--datastore-certfile {{ k3s_datastore_certfile }}
|
||||
{% endif %}
|
||||
{% if k3s_datastore_keyfile is defined and k3s_datastore_keyfile %}
|
||||
--datastore-keyfile {{ k3s_datastore_keyfile }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if k3s_dqlite_datastore is defined and k3s_dqlite_datastore %}
|
||||
{% if k3s_primary_control_node is defined and k3s_primary_control_node %}
|
||||
--cluster-init
|
||||
{% else %}
|
||||
--server https://{{ k3s_control_node_address }}:{{ k3s_https_port }}
|
||||
--token {{ k3s_control_token }}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
agent
|
||||
|
|
Loading…
Reference in a new issue