Andy Luo
Andy Luo

Reputation: 305

Kubernetes CRD Finalizer

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?

Upvotes: 4

Views: 5815

Answers (1)

Emruz Hossain
Emruz Hossain

Reputation: 5528

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.

Upvotes: 5

Related Questions