Home > OS >  Manage resources generated by other resources
Manage resources generated by other resources

Time:07-06

I am working with someone else's kubernetes application. It has a long-running Deployment whose first action upon beginning to run is to create several additional, non-workload, cluster resources (ValidatingWebhookConfigurations and MutatingWebhookConfigurations in this case).

I would like for the generated resources to be deleted when their parent Deployment is deleted. Please assume that I don't have control over how the generated manifests are deployed, but do have control over their contents.

Questions:

  • Can my goal be achieved with plain kubernetes?
    • In other words, can the generated resources be modified to be deleted when kubectl delete deployment parent-deployment is called?
    • This is preferable to handling this via Helm since some people may deploy the application using a different deployment tool.
  • Alternatively, is there a good way to handle this with Helm if parent-deployment is deployed as part of a helm chart?
    • Can I just add helm's labels to the generated resources to make Helm aware of the new resources?
    • I, personally, will deploy the application using a Helm chart so a Helm-based solution will solve my immediate problem but won't help people who deploy the application using a different method.

CodePudding user response:

You can use owner references and finalizers to create parent/child relationships between resources that allow you to clean up child resources when parent resources are deleted.

Current docs: https://kubernetes.io/docs/concepts/overview/working-with-objects/owners-dependents/

  • Related