Last active
October 1, 2019 14:40
-
-
Save toopay/22546f0c9974394697785b9a6d77d1e7 to your computer and use it in GitHub Desktop.
Revisions
-
toopay revised this gist
Oct 1, 2019 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,7 @@ #!/bin/bash concurrency_count=2 # Ensure to have correct current-context on your kubeconfig KUBECONFIG=~/.kube/config nodes_draining(){ ps -ef |grep "[k]ubectl drain" -
toopay revised this gist
Oct 1, 2019 . 1 changed file with 13 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,19 @@ #!/bin/bash concurrency_count=2 #KUBECONFIG=$(git rev-parse --show-toplevel)/k8s/secrets/kubeconfig\.dev KUBECONFIG=~/.kube/config #KUBECONFIG=$(git rev-parse --show-toplevel)/kubernetes/qa/kubeconfig nodes_draining(){ ps -ef |grep "[k]ubectl drain" return $? } wait_for_replace_confirmation(){ confirmation=true while $confirmation do read -r -p "Please replace nodes and confirm completion [Y/yes]" input case $input in [yY][eE][sS]|[yY]) echo "Replace confirmed. Proceeding" @@ -24,7 +25,7 @@ wait_for_reboot_confirmation(){ esac done } node_private_ips(){ private_ips=() for node in "${active_rolling_nodes[@]}"; do @@ -33,17 +34,18 @@ node_private_ips(){ done echo ${private_ips[@]} } roll_nodeset(){ echo "Draining Nodes: ${active_rolling_nodes[@]}" while nodes_draining; do echo "Waiting on draining nodes..." sleep 5 done echo "Please Execute Node Replace: $(node_private_ips)" wait_for_replace_confirmation echo "Uncordoning ${#active_rolling_nodes[@]} nodes" } kube_nodes=($(kubectl --kubeconfig=${KUBECONFIG} get nodes |tail -n +2 |grep -v master |awk '{print $1}')) active=1 active_rolling_nodes=() @@ -61,5 +63,5 @@ for node in "${kube_nodes[@]}"; do active=1 fi done roll_nodeset $active_rolling_nodes -
toopay created this gist
Sep 30, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ #!/bin/bash concurrency_count=2 # Ensure your current-context pointing to correct env KUBECONFIG=~/.kube/config nodes_draining(){ ps -ef |grep "[k]ubectl drain" return $? } wait_for_reboot_confirmation(){ confirmation=true while $confirmation do read -r -p "Please replace nodes and confirm completion [Y/yes]" input case $input in [yY][eE][sS]|[yY]) echo "Replace confirmed. Proceeding" confirmation=false ;; *) echo "Invalid input..." ;; esac done } node_private_ips(){ private_ips=() for node in "${active_rolling_nodes[@]}"; do internal_ip="$(kubectl --kubeconfig=${KUBECONFIG} describe node $node |grep InternalIP |awk '{print $2}')" private_ips=("${private_ips[@]}" "$internal_ip") done echo ${private_ips[@]} } roll_nodeset(){ echo "Draining Nodes: ${active_rolling_nodes[@]}" while nodes_draining; do echo "Waiting on draining nodes..." sleep 5 done echo "Please Execute Node Replace: $(node_private_ips)" wait_for_reboot_confirmation } kube_nodes=($(kubectl --kubeconfig=${KUBECONFIG} get nodes |tail -n +2 |grep -v master |awk '{print $1}')) active=1 active_rolling_nodes=() for node in "${kube_nodes[@]}"; do echo "CurrentNode: ${node}" if [[ $active < $concurrency_count ]]; then kubectl --kubeconfig=${KUBECONFIG} drain --ignore-daemonsets ${node} & active_rolling_nodes=("${active_rolling_nodes[@]}" "$node") active=$(expr $active + 1) else kubectl --kubeconfig=${KUBECONFIG} drain --ignore-daemonsets ${node} active_rolling_nodes=("${active_rolling_nodes[@]}" "$node") roll_nodeset $active_rolling_nodes active_rolling_nodes=() active=1 fi done roll_nodeset $active_rolling_nodes