4

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?

1 Answer 1

5

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.

  1. I have used Initializer to add busybox sidecar or finalizer to underlying pods. See here.
  2. When a 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.
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.