From 3232e2743e5e7f3f3c86b07553677856e41f9db1 Mon Sep 17 00:00:00 2001 From: rongzhang Date: Thu, 21 Jun 2018 06:17:03 +0000 Subject: [PATCH] Add manage swap on the worker node --- roles/kubernetes/preinstall/tasks/main.yml | 4 ++++ roles/kubernetes/preinstall/tasks/swapoff.yml | 10 ++++++++++ roles/kubespray-defaults/defaults/main.yaml | 2 ++ 3 files changed, 16 insertions(+) create mode 100644 roles/kubernetes/preinstall/tasks/swapoff.yml diff --git a/roles/kubernetes/preinstall/tasks/main.yml b/roles/kubernetes/preinstall/tasks/main.yml index 0a994e8e2..88eed5f99 100644 --- a/roles/kubernetes/preinstall/tasks/main.yml +++ b/roles/kubernetes/preinstall/tasks/main.yml @@ -1,4 +1,8 @@ --- +# Disable swap +- import_tasks: swapoff.yml + when: disable_swap + - import_tasks: verify-settings.yml tags: - asserts diff --git a/roles/kubernetes/preinstall/tasks/swapoff.yml b/roles/kubernetes/preinstall/tasks/swapoff.yml new file mode 100644 index 000000000..345e75825 --- /dev/null +++ b/roles/kubernetes/preinstall/tasks/swapoff.yml @@ -0,0 +1,10 @@ +--- +- name: Remove swapfile from /etc/fstab + mount: + name: swap + fstype: swap + state: absent + +- name: Disable swap + command: swapoff -a + when: ansible_swaptotal_mb > 0 diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml index adeb84dc6..41016fe6d 100644 --- a/roles/kubespray-defaults/defaults/main.yaml +++ b/roles/kubespray-defaults/defaults/main.yaml @@ -12,6 +12,8 @@ kube_api_anonymous_auth: false # Default value, but will be set to true automatically if detected is_atomic: false +# optional disable the swap +disable_swap: false ## Change this to use another Kubernetes version, e.g. a current beta release kube_version: v1.10.2