From 848a5457ff5607a5e288cb41868338aa5279f02e Mon Sep 17 00:00:00 2001 From: Xan Manning Date: Sat, 30 May 2020 15:16:20 +0100 Subject: [PATCH] Add option for unsupported single node with database backend. Issue #27 --- README.md | 10 ++++++++-- defaults/main.yml | 3 +++ tasks/build/preconfigure-k3s.yml | 1 + tasks/validate/check-master-count.yml | 1 + tasks/validate/main.yml | 4 +++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1c7b1f9..d076cc0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ consistency. | `k3s_server_manifests_dir` | Path for place the `k3s_server_manifests_templates`. | `/var/lib/rancher/k3s/server/manifests` | | `k3s_server_manifests_templates` | A list of Auto-Deploying Manifests Templates. | [] | | `k3s_use_experimental` | Allow the use of experimental features in k3s. | `false` | +| `k3s_use_unsupported_config` | Allow the use of unsupported configurations in k3s. | `false` | | `k3s_non_root` | Install k3s as non-root user. See notes below. | `false` | | `k3s_control_workers` | Are control hosts also workers? | `true` | | `k3s_cluster_cidr` | Network CIDR to use for pod IPs | 10.42.0.0/16 | @@ -133,7 +134,8 @@ To install k3s as non root you must not use `become: true`. The intention of this variable is to run a single node development environment. At the time of release v1.0.1, rootless is still experimental. -You must also ensure that you set `k3s_use_experimental` to `true`. +You must also ensure that you set both `k3s_use_experimental` +and `k3s_use_unsupported_config` to `true`. Additionally `k3s_install_dir` must be writable by your user. @@ -169,7 +171,7 @@ Below are variables that are set against specific hosts in your inventory. #### Important note about `k3s_control_node` and High Availability (HA) By default only one host will be defined as a control node by Ansible, If you -do not set a host as a control node, the role will automatically delegate +do not set a host as a control node, this role will automatically delegate the first play host as a control node (master). This is not suitable for use in a Production workload. @@ -182,6 +184,10 @@ the play hosts. See: [High Availability with an External DB](https://rancher.com/docs/k3s/latest/en/installation/ha/) +It is also possible, though not supported, to run a single K3s master with a +`k3s_datastore_endpoint` defined. As this is not a typically supported +configuration you will need to set `k3s_use_unsupported_config` to `true`. + Since K3s v1.0.0 it is possible to use DQLite as the backend database, and this is done by setting `k3s_dqlite_datastore` to true. As this is an experimental feature you will also need to set `k3s_use_experimental` to true. diff --git a/defaults/main.yml b/defaults/main.yml index d348e5e..d55e44e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -29,6 +29,9 @@ k3s_server_manifests_templates: [] # Use experimental features in k3s? k3s_use_experimental: false +# Allow for unsupported configurations in k3s? +k3s_use_unsupported_config: false + # Use a database or etcd cluster to enable HA. Examples below: # MySQL: # k3s_datastore_endpoint "mysql://username:password@tcp(hostname:3306)/database-name" diff --git a/tasks/build/preconfigure-k3s.yml b/tasks/build/preconfigure-k3s.yml index f75b1a9..30e7af9 100644 --- a/tasks/build/preconfigure-k3s.yml +++ b/tasks/build/preconfigure-k3s.yml @@ -46,6 +46,7 @@ @@@ P_{{ hostvars[item].k3s_primary_control_node | default(False) }} create: true + regexp: "^{{ item }} @@@ {{ hostvars[item].ansible_host | default(hostvars[item].ansible_fqdn) }}" loop: "{{ play_hosts }}" when: hostvars[item].k3s_control_node is defined diff --git a/tasks/validate/check-master-count.yml b/tasks/validate/check-master-count.yml index 8e248ca..56693b4 100644 --- a/tasks/validate/check-master-count.yml +++ b/tasks/validate/check-master-count.yml @@ -9,6 +9,7 @@ success_msg: "Control plane configuration is valid." fail_msg: "Control plane configuration is invalid. Please see notes about k3s_control_node and HA in README.md." when: k3s_controller_count | length == 1 + and not k3s_use_unsupported_config - name: Check the conditions when multiple controllers are defined assert: diff --git a/tasks/validate/main.yml b/tasks/validate/main.yml index ac0fe9f..3de3cf5 100644 --- a/tasks/validate/main.yml +++ b/tasks/validate/main.yml @@ -3,6 +3,8 @@ - import_tasks: check-variables.yml - import_tasks: check-experimental-variables.yml - import_tasks: check-unsupported-rootless.yml - when: k3s_non_root is defined and k3s_non_root + when: k3s_non_root is defined + and k3s_non_root + and k3s_use_unsupported_config - import_tasks: check-master-count.yml when: k3s_build_cluster is defined and k3s_build_cluster