Created
January 24, 2026 22:17
-
-
Save jkeam/52a16ad08c7118a7bb53f3d39a3c3acc to your computer and use it in GitHub Desktop.
Script to shutdown OpenShift
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 characters
| #!/bin/bash | |
| echo "Start the cluster before this date" | |
| oc -n openshift-kube-apiserver-operator get secret kube-apiserver-to-kubelet-signer -o jsonpath='{.metadata.annotations.auth\.openshift\.io/certificate-not-after}' | |
| echo "" | |
| echo "Marking nodes as unscheduable" | |
| for node in $(oc get nodes -o jsonpath='{.items[*].metadata.name}'); do | |
| echo ${node} | |
| oc adm cordon ${node} | |
| # oc adm uncordon ${node} is the opposite command to run after boot and control plane is back up | |
| done | |
| echo "Evacuating pods" | |
| for node in $(oc get nodes -l node-role.kubernetes.io/worker -o jsonpath='{.items[*].metadata.name}'); do | |
| echo ${node} | |
| oc adm drain ${node} --delete-emptydir-data --ignore-daemonsets=true --timeout=15s --force | |
| done | |
| echo "Shutting down nodes" | |
| for node in $(oc get nodes -o jsonpath='{.items[*].metadata.name}'); do | |
| oc debug node/${node} -- chroot /host shutdown -h 1 | |
| done | |
| # References | |
| # Shutting down: https://docs.redhat.com/en/documentation/openshift_container_platform/4.20/html/backup_and_restore/graceful-shutdown-cluster | |
| # Starting up: https://docs.redhat.com/en/documentation/openshift_container_platform/4.20/html/backup_and_restore/graceful-restart-cluster |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment