From 471589f1f4e799e01daad752e672271b5ecb5fc9 Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Tue, 5 Nov 2019 14:34:38 +0300 Subject: [PATCH] Scale down coredns created by kubeadm upgrade to 0 replicas (#5308) Change-Id: I128b0f9c1acbb956d9a6c4e5510b45a36e296af7 --- roles/kubernetes/master/defaults/main/main.yml | 3 +++ .../kubernetes/master/tasks/kubeadm-upgrade.yml | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/roles/kubernetes/master/defaults/main/main.yml b/roles/kubernetes/master/defaults/main/main.yml index 4cdd20979..c9293ffc6 100644 --- a/roles/kubernetes/master/defaults/main/main.yml +++ b/roles/kubernetes/master/defaults/main/main.yml @@ -44,6 +44,9 @@ discovery_timeout: 5m0s # Instruct first master to refresh kubeadm token kubeadm_refresh_token: true +# Scale down coredns replicas to 0 if not using coredns dns_mode +kubeadm_scale_down_coredns_enabled: true + # audit support kubernetes_audit: false # path to audit log file diff --git a/roles/kubernetes/master/tasks/kubeadm-upgrade.yml b/roles/kubernetes/master/tasks/kubeadm-upgrade.yml index b231528fb..ec9b8cf0d 100644 --- a/roles/kubernetes/master/tasks/kubeadm-upgrade.yml +++ b/roles/kubernetes/master/tasks/kubeadm-upgrade.yml @@ -37,3 +37,20 @@ - '"field is immutable" not in kubeadm_upgrade.stderr' - kubeadm_upgrade.stdout_lines | length > 1 notify: Master | restart kubelet + +# FIXME: https://github.com/kubernetes/kubeadm/issues/1318 +- name: kubeadm | scale down coredns replicas to 0 if not using coredns dns_mode + command: >- + {{ bin_dir }}/kubectl + --kubeconfig /etc/kubernetes/admin.conf + -n kube-system + scale deployment/coredns --replicas 0 + register: scale_down_coredns + retries: 6 + delay: 5 + until: scale_down_coredns is succeeded + when: + - inventory_hostname == groups['kube-master']|first + - kubeadm_scale_down_coredns_enabled + - dns_mode not in ['coredns', 'coredns_dual'] + changed_when: false