Created
January 30, 2020 19:06
-
-
Save ekristen/0d10a85013a828bb30c7287288caa8fa to your computer and use it in GitHub Desktop.
Shell One Liner to Remove Bad Finalizer From Kubernetes Resources
This file contains 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
# Swap pod for any resource you need to iterate over. (ie daemonset, deployment) | |
kubectl get pods --all-namespaces | tail -n+2 | awk '{print $1 " " $2}' | xargs -L1 bash -c "kubectl patch -n \$0 pod/\$1 --type=merge -p \$(kubectl get -n \$0 pod/\$1 -o json | jq -Mcr '.metadata.finalizers // [] | {metadata:{finalizers:map(select(. != \"name-of-bad-finalizer\"))}}')" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to be safe from race conditions and lost updates, you got to use
kubectl replace
and pass whole resource so that resourceVersion is checked. Something like this for a single-resource version: