hjacobs / kube-janitor

Clean up (delete) Kubernetes resources after a configured TTL (time to live)
GNU General Public License v3.0
473 stars 40 forks source link

Deleting Helm releases #48

Open TBeijen opened 4 years ago

TBeijen commented 4 years ago

Kube-janitor seems perfect for auto-cleaning of temp. feature deploys. But... we use Helm. So it would remove the resources and leave the release data (secret objects) dangling.

Possible ways to cleanup helm releases could be:

Determine release and use helm to uninstall

Some pros/cons:

Find helm release secret object and remove that as well

Some pros/cons:

Any implementation would obviously be 'opt in' and might require some additional config options or logic, e.g. an annotation specifying the label to extract the helm release from.

I'd like to hear your thoughts. Personally I think the 2nd approach would be a fit for kube-janitor while 1st approach has risk of embedding what would become a parallel completely new implementation.

Coming days (given time, 🎄after all) I'll try to run some tests to see how Helm copes with possible dangling resources, while release data has been removed.

hjacobs commented 4 years ago

My 2cts: I would like to avoid any Helm dependency if possible, but some additional logic for cleaning up Helm resources would be fine with me.

runningman84 commented 4 years ago

What about cleaning custom resources used by Helm Operator? You would just have to delete some kubernetes object... helm itself would be called by the operator

TBeijen commented 4 years ago

As janitor iterates all api groups, cleaning those custom resources and then have Helm Operator do the rest, looks like a very good approach. :)

... now only if we used Helm Operator.

(Having explored the 'delete helm secret' approach a bit more: That will be tricky. Individual resources can expire at different times. You'd only want to delete the helm release secret if all associated resources are removed as well)

sryabkov commented 4 years ago

We could not use kube-janitor with helm 2 even though we were deploying everything to the same namespace. Having kube-janitor delete the namespace would leave helm releases still in the cluster. However, helm 3 changes this because helm releases now belong to a namespace instead of being global. Because of that, having kube-janitor support removal of helm releases is now less of an issue. By tweaking your Kubernetes namespace management, you can put kube-janitor annotation on the namespace, and that would delete the helm releases in that namespace when the namespace gets wiped out.

hjacobs commented 4 years ago

@sryabkov good to hear, I'm not a Helm user myself, but Helm 3 sounds like a step into the right direction :smile:

bobo333 commented 4 years ago

The one caveat to the approach @sryabkov mentions, is non-namespaced resources in the helm release (ex: ClusterRoles) will not get deleted by deleting the namespace, not a huge problem but it's worth mentioning / being aware of.

jspiro commented 4 years ago

@sryabkov Have you tried this yet – does k-j delete the charts and completely wipe out the helm release? I.e. it should not show up in helm list after it clears the namespace.

If it doesn't work, what is missing from k-j?

Stono commented 4 years ago

The one caveat to the approach @sryabkov mentions, is non-namespaced resources in the helm release (ex: ClusterRoles) will not get deleted by deleting the namespace, not a huge problem but it's worth mentioning / being aware of.

This would be the biggest blocker for me, the purpose of janitor is to clean up your cluster, not leave things lying around :-)

I appreciate you don't want a helm dependency, but is used so extensively now - would it be such a bad thing to have it as an option?

Some use cases for us:

sryabkov commented 4 years ago

@jspiro We are using Helm 3, and Helm 3 releases are deployed to a particular namespace. Helm 3 stores all of the state/history data in Kubernetes secrets inside the namespace. If you delete the namespace, you delete all resources in the namespace, including all Helm 3 state data.

I am not sure what's going to happen if you have a cluster-wide resource in a chart and then you delete the namespace to which the chart was deployed (using Helm 3). My guess would be that the cluster-wide resource would still be around. We don't mix namespaced resources and cluster-wide resources in one chart.

jspiro commented 4 years ago

@sryabkov Awesome, that very encouraging. I'll be presenting a neat project in a CNCF webinar next month that partly relies upon helm/skaffold cleanup being complete. Stay tuned!