From 2307546be20f28a811fc9125ac6e88645f1a6b71 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 15:10:19 +0100 Subject: [PATCH 01/12] add support place k8s manifests to the nodes --- defaults/main.yml | 7 +++++++ tasks/build/preconfigure-k3s-auto-deploying-manifests.yml | 5 +++++ tasks/state-installed.yml | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 tasks/build/preconfigure-k3s-auto-deploying-manifests.yml diff --git a/defaults/main.yml b/defaults/main.yml index e4f27a2..87337e6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,6 +14,13 @@ k3s_github_url: https://github.com/rancher/k3s # Installation directory for k3s k3s_install_dir: /usr/local/bin +# Path for additional Kubernetes Manifests +# https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests +k3s_server_manifests_dir: /var/lib/rancher/k3s/server/manifests + +# a list of templates used for preconfigure the CLuster. +k3s_server_manifests_templates: [] + # Use experimental features in k3s? k3s_use_experimental: false diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml new file mode 100644 index 0000000..3c76207 --- /dev/null +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -0,0 +1,5 @@ +- name: Copy Auto-Deploying Manifests to Cluster Master + template: + src: "{{ item }}" + dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2','') }}" + with_items: "{{ k3s_server_manifests_templates }}" diff --git a/tasks/state-installed.yml b/tasks/state-installed.yml index 1a71b74..d85396b 100644 --- a/tasks/state-installed.yml +++ b/tasks/state-installed.yml @@ -28,6 +28,8 @@ - import_tasks: build/download-k3s.yml +- import_tasks: build/preconfigure-k3s-auto-deploying-manifests.yml + - import_tasks: build/install-k3s.yml - import_tasks: build/configure-k3s-cluster.yml From 2b646e4e4fd177e08997bc23d122345093bb508e Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 15:44:28 +0100 Subject: [PATCH 02/12] update task documentation and add new config parameters to the Readme --- README.md | 29 ++++++++++--------- ...configure-k3s-auto-deploying-manifests.yml | 5 +++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 573f7e6..0f7a773 100644 --- a/README.md +++ b/README.md @@ -107,19 +107,22 @@ 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_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` | -| `k3s_tls_san` | Add additional hosname or IP as Subject Alternate Name in the TLS cert. | _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` | +| `k3s_tls_san` | Add additional hosname or IP as Subject Alternate Name in the TLS cert. | _NULL_ | +| `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. | [] | + #### Important note about `k3s_control_node` diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml index 3c76207..c61243d 100644 --- a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -1,4 +1,7 @@ -- name: Copy Auto-Deploying Manifests to Cluster Master +--- + +# https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests +- name: Copy Auto-Deploying Manifests to Cluster template: src: "{{ item }}" dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2','') }}" From b89f2f3acde4becc9810c5293e29239f94e8d09c Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 15:58:58 +0100 Subject: [PATCH 03/12] remove trailing spaces --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 87337e6..e6b67fd 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,7 +14,7 @@ k3s_github_url: https://github.com/rancher/k3s # Installation directory for k3s k3s_install_dir: /usr/local/bin -# Path for additional Kubernetes Manifests +# Path for additional Kubernetes Manifests # https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests k3s_server_manifests_dir: /var/lib/rancher/k3s/server/manifests From 2aedce03593e29c75f5bb84c002506d19709fed5 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 18:03:47 +0100 Subject: [PATCH 04/12] add first draft for running molecule test with auto manifests deployments --- .travis.yml | 4 ++++ molecule/default/playbook-auto-deploying-manifests.yml | 10 ++++++++++ molecule/default/templates/00-ns-monitoring.yml.j2 | 4 ++++ 3 files changed, 18 insertions(+) create mode 100644 molecule/default/playbook-auto-deploying-manifests.yml create mode 100644 molecule/default/templates/00-ns-monitoring.yml.j2 diff --git a/.travis.yml b/.travis.yml index 5664c3a..bacad49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,10 @@ env: - MOLECULE_DISTRO: geerlingguy/docker-fedora31-ansible:latest MOLECULE_PLAYBOOK: playbook-no-deploy.yml + # Test auto deploying manifests + - MOLECULE_DISTRO: geerlingguy/docker-ubuntu1804-ansible:latest + MOLECULE_PLAYBOOK: playbook-auto-deploying-manifests.yml + install: # Install test dependencies. - pip install molecule docker jmespath diff --git a/molecule/default/playbook-auto-deploying-manifests.yml b/molecule/default/playbook-auto-deploying-manifests.yml new file mode 100644 index 0000000..7767ecd --- /dev/null +++ b/molecule/default/playbook-auto-deploying-manifests.yml @@ -0,0 +1,10 @@ +--- +- name: Converge + hosts: all + become: true + vars: + molecule_is_test: true + k3s_server_manifests_templates: + - "ns-monitoring.yml.j2" + roles: + - role: xanmanning.k3s diff --git a/molecule/default/templates/00-ns-monitoring.yml.j2 b/molecule/default/templates/00-ns-monitoring.yml.j2 new file mode 100644 index 0000000..3335b6a --- /dev/null +++ b/molecule/default/templates/00-ns-monitoring.yml.j2 @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: monitoring \ No newline at end of file From cb13c5b4730ff1b4f35c0137b496cb79bbf188a7 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 18:56:48 +0100 Subject: [PATCH 05/12] create manifests directory if not exists --- tasks/build/preconfigure-k3s-auto-deploying-manifests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml index c61243d..e3fc17f 100644 --- a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -1,5 +1,11 @@ --- +- name: ensure that the manifests directory exists, if required + file: + state: directory + path: "{{ k3s_server_manifests_dir }}" + when: k3s_server_manifests_templates | length > 0 + # https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests - name: Copy Auto-Deploying Manifests to Cluster template: From 1dd9297de4ab4ff9101c50a02935c7d2a61213fc Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 19:39:11 +0100 Subject: [PATCH 06/12] change template path for molecule test --- molecule/default/playbook-auto-deploying-manifests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/default/playbook-auto-deploying-manifests.yml b/molecule/default/playbook-auto-deploying-manifests.yml index 7767ecd..0522817 100644 --- a/molecule/default/playbook-auto-deploying-manifests.yml +++ b/molecule/default/playbook-auto-deploying-manifests.yml @@ -5,6 +5,6 @@ vars: molecule_is_test: true k3s_server_manifests_templates: - - "ns-monitoring.yml.j2" + - "molecule/default/templates/ns-monitoring.yml.j2" roles: - role: xanmanning.k3s From 227b24c11786a8482ddb8eeca2263e815069cbf7 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 20:03:16 +0100 Subject: [PATCH 07/12] Update defaults/main.yml Co-Authored-By: Xan Manning --- defaults/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index e6b67fd..19c95ff 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,7 +18,7 @@ k3s_install_dir: /usr/local/bin # https://rancher.com/docs/k3s/latest/en/advanced/#auto-deploying-manifests k3s_server_manifests_dir: /var/lib/rancher/k3s/server/manifests -# a list of templates used for preconfigure the CLuster. +# A list of templates used for preconfigure the cluster. k3s_server_manifests_templates: [] # Use experimental features in k3s? From 2e03ea2e6fbc15108cf4f40973b21677bc245d06 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 20:03:29 +0100 Subject: [PATCH 08/12] Update tasks/build/preconfigure-k3s-auto-deploying-manifests.yml Co-Authored-By: Xan Manning --- tasks/build/preconfigure-k3s-auto-deploying-manifests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml index e3fc17f..c0b076b 100644 --- a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -1,6 +1,6 @@ --- -- name: ensure that the manifests directory exists, if required +- name: Ensure that the manifests directory exists, if required file: state: directory path: "{{ k3s_server_manifests_dir }}" From b896e90704dc27dcfde3a3ccb9abc8ebae007aae Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 20:03:58 +0100 Subject: [PATCH 09/12] Update tasks/build/preconfigure-k3s-auto-deploying-manifests.yml Co-Authored-By: Xan Manning --- tasks/build/preconfigure-k3s-auto-deploying-manifests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml index c0b076b..719cd20 100644 --- a/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml +++ b/tasks/build/preconfigure-k3s-auto-deploying-manifests.yml @@ -11,4 +11,4 @@ template: src: "{{ item }}" dest: "{{ k3s_server_manifests_dir }}/{{ item | basename | replace('.j2','') }}" - with_items: "{{ k3s_server_manifests_templates }}" + loop: "{{ k3s_server_manifests_templates }}" From a73a1fbdefacc1478a4433edabedbcb7a779bef3 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 20:04:11 +0100 Subject: [PATCH 10/12] Update molecule/default/playbook-auto-deploying-manifests.yml Co-Authored-By: Xan Manning From 2d0dc8db690aeab9c812c11b8a1722a89e53d4cf Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 20:04:26 +0100 Subject: [PATCH 11/12] Update molecule/default/templates/00-ns-monitoring.yml.j2 Co-Authored-By: Xan Manning --- molecule/default/templates/00-ns-monitoring.yml.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/default/templates/00-ns-monitoring.yml.j2 b/molecule/default/templates/00-ns-monitoring.yml.j2 index 3335b6a..d325236 100644 --- a/molecule/default/templates/00-ns-monitoring.yml.j2 +++ b/molecule/default/templates/00-ns-monitoring.yml.j2 @@ -1,4 +1,4 @@ apiVersion: v1 kind: Namespace metadata: - name: monitoring \ No newline at end of file + name: monitoring From 5331e2242532c512adeef2e60cd91c764fd60df5 Mon Sep 17 00:00:00 2001 From: nolte Date: Sat, 11 Jan 2020 23:51:52 +0100 Subject: [PATCH 12/12] fix path, missing prefix --- molecule/default/playbook-auto-deploying-manifests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/molecule/default/playbook-auto-deploying-manifests.yml b/molecule/default/playbook-auto-deploying-manifests.yml index 0522817..72b26be 100644 --- a/molecule/default/playbook-auto-deploying-manifests.yml +++ b/molecule/default/playbook-auto-deploying-manifests.yml @@ -5,6 +5,6 @@ vars: molecule_is_test: true k3s_server_manifests_templates: - - "molecule/default/templates/ns-monitoring.yml.j2" + - "molecule/default/templates/00-ns-monitoring.yml.j2" roles: - role: xanmanning.k3s