Kubernetes Supports Finalizer in CR to prevent hard deletion. I had a hard time to find sample code though. Can someone please point to real code snippet?
This sample repository show demo use of Finalizer
and Initializer
. Finalizer are used here for garbage collection.
Repostory: k8s-initializer-finalizer-practice
Here, I have created a custom controller for pods, just like Deployment.
Initializer
to add busybox
sidecar or finalizer
to underlying pods. See here.CustomDeployment
crd is deleted, kubernetes set DeletionTimestamp
but does not delete it if it has finalizer. Then controller checks if it has finalizer. If it has finalizer, it deletes its pod and remove the finalizer. Then the crd terminate. See here.