Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes CRD Finalizer

Tags:

kubernetes

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?

like image 255
Andy Luo Avatar asked Sep 01 '25 03:09

Andy Luo


1 Answers

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.
like image 177
Emruz Hossain Avatar answered Sep 03 '25 01:09

Emruz Hossain