From 8f834557f7ccaa38b477853b7b1caf7c91784207 Mon Sep 17 00:00:00 2001
From: Petr OspalĂ˝
Date: Thu, 22 Aug 2019 17:33:07 +0200
Subject: Add configurable etcd storage feature
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Plus the option to have etcd on tmpfs (volatile storage) for little
bigger (maybe) speed (NOT FOR PRODUCTION DEPLOYMENT!).
Issue-ID: OOM-2058
Change-Id: I0bbfc4fbae7f6b46e2fae49656437cd6748efd49
Signed-off-by: Petr OspalĂ˝
---
ansible/roles/rke/defaults/main.yml | 40 ++++++++++++++++++++++++++++++
ansible/roles/rke/tasks/rke_etcd.yml | 9 +++++++
ansible/roles/rke/templates/cluster.yml.j2 | 7 ++++++
3 files changed, 56 insertions(+)
create mode 100644 ansible/roles/rke/tasks/rke_etcd.yml
(limited to 'ansible/roles')
diff --git a/ansible/roles/rke/defaults/main.yml b/ansible/roles/rke/defaults/main.yml
index 2f160fc2..d9c044b6 100644
--- a/ansible/roles/rke/defaults/main.yml
+++ b/ansible/roles/rke/defaults/main.yml
@@ -6,6 +6,46 @@ kube_config_dir: "{{ ansible_env.HOME }}/.kube"
cluster_config_dir: "{{ app_data_path }}/cluster"
# Whether dashboard is exposed.
rke_dashboard_exposed: true
+rke_etcd:
+ # By default rke creates bind mount:
+ # /var/lib/etcd -> /var/lib/rancher/etcd
+ # These parameters provide means of modifying it:
+ # - custom bind mount
+ # - option to use volatile storage
+
+ # Custom bind mount
+ #
+ # I did not find a proper way (in the docs) how to override the
+ # defaults so I just abuse the extra_* args for the rke etcd
+ # service. It means that it will create another mount point in the
+ # container and you should use different pathnames than default...
+ #
+ # The custom bind mount is by default disabled.
+ enabled_custom_etcd_storage: false
+
+ # Applicated only if custom mount is enabled.
+ # Paths must be absolute (start with '/')
+ #
+ # Path on the kubernetes/etcd node
+ storage_path: /var/lib/etcd-custom
+ # Path inside the container where it is mounted.
+ storage_mountpoint: /var/lib/rancher/etcd-custom
+
+ # On top of it (with or without custom mount) you can use tmpfs
+ # as a volatile storage.
+ #
+ # CAUTION: This will create temporary filesystem (in the memory)
+ # so if an etcd node will be poweroff then all etcd data will be
+ # lost!!!
+ #
+ # Don't use unless you don't care about your cluster!
+ #
+ # This is intended as an attempt to make deployment little bit
+ # more faster...by default it is disabled.
+ enabled_unsafe_volatile_storage: false
+ # Size of the volatile storage - tmpfs (this will eat your RAM)
+ tmpfs_size: 5G
+
rke:
# rke (rancher) images
etcd: rancher/coreos-etcd:v3.2.24-rancher1
diff --git a/ansible/roles/rke/tasks/rke_etcd.yml b/ansible/roles/rke/tasks/rke_etcd.yml
new file mode 100644
index 00000000..3dddf9e8
--- /dev/null
+++ b/ansible/roles/rke/tasks/rke_etcd.yml
@@ -0,0 +1,9 @@
+---
+- name: "Mount tmpfs as etcd storage - non-persistent data (BEWARE)"
+ mount:
+ path: "{{ rke_etcd.storage_path if rke_etcd.enabled_custom_etcd_storage else '/var/lib/etcd' }}"
+ src: tmpfs
+ fstype: tmpfs
+ opts: "defaults,size={{ rke_etcd.tmpfs_size }},mode=700"
+ state: mounted
+ when: rke_etcd.enabled_unsafe_volatile_storage
diff --git a/ansible/roles/rke/templates/cluster.yml.j2 b/ansible/roles/rke/templates/cluster.yml.j2
index 2012ab92..737d306f 100644
--- a/ansible/roles/rke/templates/cluster.yml.j2
+++ b/ansible/roles/rke/templates/cluster.yml.j2
@@ -25,8 +25,15 @@ nodes:
services:
etcd:
image: ""
+{% if rke_etcd.enabled_custom_etcd_storage %}
+ extra_args:
+ data-dir: "{{ rke_etcd.storage_mountpoint }}"
+ extra_binds:
+ - "{{ rke_etcd.storage_path }}:{{ rke_etcd.storage_mountpoint }}"
+{% else %}
extra_args: {}
extra_binds: []
+{% endif %}
extra_env: []
external_urls: []
ca_cert: ""
--
cgit 1.2.3-korg