fix: kubectl drain 参数版本差异导致失败的问题

pull/1109/head
gjmzj 2021-10-26 19:24:25 +08:00
parent d494d1c2a1
commit 6786d45f3c
5 changed files with 38 additions and 4 deletions

View File

@ -29,6 +29,8 @@ CERT_EXPIRY: "438000h"
CLUSTER_NAME: "cluster1"
CONTEXT_NAME: "context-{{ CLUSTER_NAME }}"
# k8s version
K8S_VER: "__k8s_ver__"
############################
# role:etcd

6
ezctl
View File

@ -140,7 +140,8 @@ function new() {
sed -i "s/_cluster_name_/$1/g" "clusters/$1/hosts"
cp example/config.yml "clusters/$1/config.yml"
logger debug "set version of common plugins"
logger debug "set versions"
k8sVer=$(grep 'K8S_BIN_VER=v' ezdown|cut -d'v' -f2)
calicoVer=$(grep 'calicoVer=' ezdown|cut -d'=' -f2)
ciliumVer=$(grep 'ciliumVer=' ezdown|cut -d'=' -f2)
flannelVer=$(grep 'flannelVer=' ezdown|cut -d'=' -f2)
@ -160,7 +161,8 @@ function new() {
grep registry-mirrors /etc/docker/daemon.json > /dev/null 2>&1 || { logger debug "disable registry mirrors"; registryMirror=false; }
sed -i -e "s/__flannel__/$flannelVer/g" \
sed -i -e "s/__k8s_ver__/$k8sVer/g" \
-e "s/__flannel__/$flannelVer/g" \
-e "s/__calico__/$calicoVer/g" \
-e "s/__cilium__/$ciliumVer/g" \
-e "s/__kube_ovn__/$kubeOvnVer/g" \

View File

@ -5,8 +5,23 @@
- fail: msg="you CAN NOT delete the last member of kube_master!"
when: "groups['kube_master']|length < 2 and NODE_TO_DEL in groups['kube_master']"
- name: 注册变量 K8S 主版本
shell: echo {{ K8S_VER }}|awk -F. '{print $1"."$2}'
register: K8S_VER_MAIN
- name: 设置kubectl drain 参数
set_fact: DRAIN_OPT="--delete-emptydir-data --ignore-daemonsets --force"
when: "K8S_VER_MAIN.stdout|float > 1.19"
- name: 设置kubectl drain 参数
set_fact: DRAIN_OPT="--delete-local-data --ignore-daemonsets --force"
when: "K8S_VER_MAIN.stdout|float < 1.20"
- name: debug info
debug: var="DRAIN_OPT"
- name: run kubectl drain @{{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} --ignore-daemonsets --delete-emptydir-data --force"
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}"
#ignore_errors: true
- name: clean node {{ NODE_TO_DEL }}

View File

@ -5,8 +5,23 @@
- fail: msg="you CAN NOT delete the last member of kube_master!"
when: "groups['kube_master']|length < 2 and NODE_TO_DEL in groups['kube_master']"
- name: 注册变量 K8S 主版本
shell: echo {{ K8S_VER }}|awk -F. '{print $1"."$2}'
register: K8S_VER_MAIN
- name: 设置kubectl drain 参数
set_fact: DRAIN_OPT="--delete-emptydir-data --ignore-daemonsets --force"
when: "K8S_VER_MAIN.stdout|float > 1.19"
- name: 设置kubectl drain 参数
set_fact: DRAIN_OPT="--delete-local-data --ignore-daemonsets --force"
when: "K8S_VER_MAIN.stdout|float < 1.20"
- name: debug info
debug: var="DRAIN_OPT"
- name: run kubectl drain @{{ NODE_TO_DEL }}
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} --ignore-daemonsets --delete-emptydir-data --force"
shell: "{{ base_dir }}/bin/kubectl drain {{ NODE_TO_DEL }} {{ DRAIN_OPT }}"
#ignore_errors: true
- name: clean node {{ NODE_TO_DEL }}