Kubernetes CRD Finalizer

10/30/2018

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?

-- Andy Luo
kubernetes

1 Answer

10/30/2018

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.
-- Emruz Hossain
Source: StackOverflow