Skip to content

Instantly share code, notes, and snippets.

@pichuang
Last active February 19, 2021 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pichuang/a42a2a2103152ecba0238717dda8a298 to your computer and use it in GitHub Desktop.
Save pichuang/a42a2a2103152ecba0238717dda8a298 to your computer and use it in GitHub Desktop.
Shutdown OCP4.6 Gracefully
#!/bin/bash
# Ref: https://docs.openshift.com/container-platform/4.6/backup_and_restore/graceful-cluster-shutdown.html
# !!!IMPORTANT!!!
# DO THE ETCD BACKUP FISRT
# https://gist.github.com/pichuang/53aef7091245c55a91a5f0bd56fa3256
non_master_nodes=$(oc get nodes --selector='!node-role.kubernetes.io/master' -o jsonpath='{.items[*].metadata.name}')
for node in ${non_master_nodes[@]}
do
echo "==== Shut down $node ===="
ssh core@$node sudo shutdown -h 1
done
sleep 3
master_nodes=$(oc get nodes -l node-role.kubernetes.io/master -o jsonpath='{.items[*].metadata.name}')
for node in ${master_nodes[@]}
do
echo "==== Shut down $node ===="
ssh core@$node sudo shutdown -h 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment