From 26a3b2eef03569010d638178c53c1051beee90f3 Mon Sep 17 00:00:00 2001 From: Xan Manning Date: Wed, 4 Dec 2019 18:44:37 +0000 Subject: [PATCH] Added extra no-deploy options for v1.0.0 --- .travis.yml | 2 +- README.md | 36 +++++++++++++++---------- defaults/main.yml | 6 +++++ molecule/default/playbook-no-deploy.yml | 3 ++- tasks/configure-k3s-cluster.yml | 1 - templates/k3s.service.j2 | 14 ++++++++-- 6 files changed, 43 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4bcedf..a8bc7c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ env: MOLECULE_PLAYBOOK: playbook-docker.yml # Test using alternate port and using wireguard as the flannel backend - - MOLECULE_DISTRO: amazonlinux2 + - MOLECULE_DISTRO: debian10 MOLECULE_PLAYBOOK: playbook-docker-altport-wireguard.yml # Test disabling all deployments diff --git a/README.md b/README.md index fc5757c..9e2cbdf 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,15 @@ This role has been tested on Ansible 2.6.0+ against the following Linux Distribu ## Disclaimer -:warning: Not suitable for production use. +:warning: May not be suitable for production use! -Whilst Rancher Labs are awesome, k3s is a fairly new project and not yet a v1.0 -release so extreme caution and operational rigor is recommended before using -this role for any serious development. +Rancher Labs is awesome and has released k3s as v1.0.0, however at the time of +creating this role I do not have a k3s cluster in production nor am I unlikely +to ever have one. Please ensure you practice extreme caution and operational +rigor before using this role for any serious workloads. + +If you have any problems please create a GitHub issue, I maintain this role in +my spare time so I cannot promise a speedy fix delivery. ## Role Variables @@ -52,6 +56,8 @@ consistency. | `k3s_cluster_domain` | Cluster Domain. | cluster.local | | `k3s_no_traefik` | Do not use Traefik | `false` | | `k3s_no_servicelb` | Do not use ServiceLB, necessary for using something like MetalLB. | `false` | +| `k3s_no_local_storage` | Do not use Local Storage | `false` | +| `k3s_no_metrics_server` | Do not deploy metrics server | `false` | | `k3s_disable_scheduler` | Disable Kubernetes default scheduler | `false` | | `k3s_disable_cloud_controller` | Disable k3s default cloud controller manager. | `false` | | `k3s_disable_network_policy` | Disable k3s default network policy controller. | `false` | @@ -81,16 +87,18 @@ Please note that this may potentially break setting up agents. Below are variables that are set against specific hosts in your inventory. -| Variable | Description | Default Value | -|-----------------------------|--------------------------------------------------------|---------------| -| `k3s_control_node` | Define the host as a control plane node, (True/False). | `false` | -| `k3s_node_name` | Define the name of this node. | `$(hostname)` | -| `k3s_flannel_interface` | Define the flannel proxy interface for this node. | _NULL_ | -| `k3s_bind_address` | Define the bind address for this node. | localhost | -| `k3s_node_ip_address` | IP Address to advertise for this node. | _NULL_ | -| `k3s_node_external_address` | External IP Address to advertise for this node. | _NULL_ | -| `k3s_node_labels` | List of node labels. | _NULL_ | -| `k3s_node_taints` | List of node taints. | _NULL_ | +| Variable | Description | Default Value | +|-----------------------------|--------------------------------------------------------|------------------------| +| `k3s_control_node` | Define the host as a control plane node, (True/False). | `false` | +| `k3s_node_name` | Define the name of this node. | `$(hostname)` | +| `k3s_node_id` | Define the ID of this node. | _NULL_ | +| `k3s_flannel_interface` | Define the flannel proxy interface for this node. | _NULL_ | +| `k3s_bind_address` | Define the bind address for this node. | localhost | +| `k3s_node_ip_address` | IP Address to advertise for this node. | _NULL_ | +| `k3s_node_external_address` | External IP Address to advertise for this node. | _NULL_ | +| `k3s_node_labels` | List of node labels. | _NULL_ | +| `k3s_node_taints` | List of node taints. | _NULL_ | +| `k3s_node_data_dir` | Folder to hold state. | `/var/lib/rancher/k3s` | #### Important note about `k3s_control_node` diff --git a/defaults/main.yml b/defaults/main.yml index 48eb706..8cb7556 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -43,6 +43,12 @@ k3s_no_traefik: false # load balancer service. k3s_no_servicelb: false +# Do not use local storage +k3s_no_local_storage: false + +# Do not deploy metrics server +k3s_no_metrics_server: false + # Disable default k3s scheduler k3s_disable_scheduler: false diff --git a/molecule/default/playbook-no-deploy.yml b/molecule/default/playbook-no-deploy.yml index 6a2115b..16a8ab4 100644 --- a/molecule/default/playbook-no-deploy.yml +++ b/molecule/default/playbook-no-deploy.yml @@ -4,10 +4,11 @@ become: true vars: molecule_is_test: true - k3s_no_flannel: true k3s_no_coredns: true k3s_no_traefik: true k3s_no_servicelb: true + k3s_no_local_storage: true + k3s_no_metrics_server: true k3s_disable_scheduler: true k3s_disable_cloud_controller: true k3s_disable_network_policy: true diff --git a/tasks/configure-k3s-cluster.yml b/tasks/configure-k3s-cluster.yml index b886a50..0ec7572 100644 --- a/tasks/configure-k3s-cluster.yml +++ b/tasks/configure-k3s-cluster.yml @@ -20,7 +20,6 @@ - name: Ensure control node is delegated to for obtaining a token set_fact: k3s_control_delegate: "{{ k3s_control_delegate_raw.stdout.split(' @@@ ')[0] }}" - when: k3s_control_node_address is not defined - name: Ensure the control node address is registered in Ansible set_fact: diff --git a/templates/k3s.service.j2 b/templates/k3s.service.j2 index 870eaa1..2a9a5e1 100644 --- a/templates/k3s.service.j2 +++ b/templates/k3s.service.j2 @@ -25,14 +25,18 @@ ExecStart={{ k3s_install_dir }}/k3s --disable-network-policy {% endif %} {% if k3s_no_flannel %} - --no-flannel + {% if k3s_release_version is version_compare('1.0.0', '<') %} + --no-flannel + {% else %} + --flannel-backend none + {% endif %} {% endif %} {% if k3s_flannel_backend != "vxlan" and not k3s_no_flannel %} --flannel-backend {{ k3s_flannel_backend }} {% endif %} {% if k3s_no_coredns is defined or k3s_no_traefik is defined or k3s_no_servicelb is defined %} {% if k3s_no_coredns or k3s_no_traefik or k3s_no_servicelb %} - {{ ' --no-deploy coredns' if k3s_no_coredns else '' }}{{ ' --no-deploy servicelb' if k3s_no_servicelb else '' }}{{ ' --no-deploy traefik' if k3s_no_traefik else '' }} + {{ ' --no-deploy coredns' if k3s_no_coredns else '' }}{{ ' --no-deploy servicelb' if k3s_no_servicelb else '' }}{{ ' --no-deploy traefik' if k3s_no_traefik else '' }}{{ ' --no-deploy local-storage' if k3s_no_local_storage else '' }}{{ ' --no-deploy metrics-server' if k3s_no_metrics_server else '' }} {% endif %} {% endif %} {% if k3s_cluster_dns is defined and k3s_cluster_dns %} @@ -46,6 +50,9 @@ ExecStart={{ k3s_install_dir }}/k3s --server https://{{ k3s_control_node_address }}:{{ k3s_https_port }} --token {{ k3s_control_token }} {% endif %} +{% if k3s_node_data_dir is defined %} + --data-dir {{ k3s_node_data_dir }} +{% endif %} {% if k3s_use_docker %} --docker {% endif %} @@ -58,6 +65,9 @@ ExecStart={{ k3s_install_dir }}/k3s {% if k3s_node_name is defined %} --node-name {{ k3s_node_name }} {% endif %} +{% if k3s_node_id is defined %} + --with-node-id {{ k3s_node_id }} +{% endif %} {% if k3s_node_ip_address is defined %} --node-ip {{ k3s_node_ip_address }} {% endif %}