<p>I am new to Kubernetes Operators. I have a general question about how to conceive of cleanup at the point of deletion.</p>
<p>Let's say the Controller is managing a resource which consists of a Deployment among other things. This Deployment writes to some external database. I'd like the items from the Database to be deleted when the resource is deleted (but not when its Pod is simply restarted - thus it can't happen as part of the application's shut down logic).</p>
<p>It seems like the database purging would have to happen in the Controller then? But this makes me a bit uneasy since it seems like this knowledge of how values are stored is the knowledge of the resource being managed, not the Controller. Is the only other good option to have the Controller send a message to the underlying application to perform its own cleanup?</p>
<p>What is the general way to handle this type of thing?</p>

vmayer
<p>Have you heard about Finalizers and <a href="https://kubernetes.io/blog/2021/05/14/using-finalizers-to-control-deletion/#owner-references" rel="nofollow noreferrer">Owner References</a> in Kubernetes? It's the Owner references describe how groups of objects are related. They are properties on resources that specify the relationship to one another, so entire trees of resources can be deleted.</p>
<p>To avoid futher copy-pasting, I will just leave the links here: <a href="https://kubernetes.io/blog/2021/05/14/using-finalizers-to-control-deletion/#understanding-finalizers" rel="nofollow noreferrer">Understanding Finalizers</a></p>
