Execute temporary treatments with Helm

When we deploy an helm chart, it’s possible that we want to do some actions before and/or after. We think about using Jobs, but they are not the best because we can’t configure easily when to execute them or about their auto deletion (cf https://dev.to…


This content originally appeared on DEV Community and was authored by Maxime Guilbert

When we deploy an helm chart, it's possible that we want to do some actions before and/or after. We think about using Jobs, but they are not the best because we can't configure easily when to execute them or about their auto deletion (cf https://dev.to/mxglt/automatically-delete-a-job-in-kubernetes-21oc).

So, if you are using Helm, we will see how to do it with Hooks.

What are hooks?

Hooks are mecanism which allows to execute some treatments at particular moments of the helm life cycle.

To define these treatments, we will add some annotations to a Kubernetes Job to define 3 things:

  • Moment where the job should be executed
  • its priority (if multiple jobs are started with the same hook)
  • How to delete it

Moment where the job should be executed

With the annotation helm.sh/hook, we can define moments where the job should be executed.

Currently, available values are :

  • pre-install : Executes after templates are rendered, but before any resources are created in Kubernetes (Not executed in an upgrade)
  • post-install : Executes after all resources are loaded into Kubernetes (Not executed in an upgrade)
  • pre-delete : Executes on a deletion request before any resources are deleted from Kubernetes
  • post-delete : Executes on a deletion request after all of the release's resources have been deleted
  • pre-upgrade : Executes on an upgrade request after templates are rendered, but before any resources are updated (Not executed in an install)
  • post-upgrade : Executes on an upgrade request after all resources have been upgraded (Not executed in an install)
  • pre-rollback : Executes on a rollback request after templates are rendered, but before any resources are rolled back
  • post-rollback : Executes on a rollback request after all resources have been modified
  • test : Executes when the Helm test subcommand is invoked

With all these possibilities, it becomes easier to :

  • install CRDs before to install an operator
  • execute script to clean something after a deletion
  • have some script to move between two versions

Example

annotations:
    "helm.sh/hook": post-install,post-upgrade

Its priority

To define the priority of a job, we must use the annotation helm.sh/hook-weight.

Its value must be a number declared as a string. This number can be positive or negative.

Example

annotations:
    "helm.sh/hook-weight": "-5"

How to delete it

After the end of a job, we want to be able to manage how it should be deleted. Helm gives us the possibility to configure it with the annotation helm.sh/hook-ddelete-policy.

3 values are available :

  • before-hook-creation : Delete the previous instance of the job before anotherhook started (default)
  • hook-succeeded : Delete the job if the hook was successful
  • hook-failed : Delete the job if the hook fails

Example

annotations:
    "helm.sh/hook-delete-policy": hook-succeeded

In conclusion, we saw that Helm gives us a little bit more dynamism which is really helpful to have a complete automated flow for an application.

Links

I hope it will help you! 🍺


This content originally appeared on DEV Community and was authored by Maxime Guilbert


Print Share Comment Cite Upload Translate Updates
APA

Maxime Guilbert | Sciencx (2023-02-27T15:12:00+00:00) Execute temporary treatments with Helm. Retrieved from https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/

MLA
" » Execute temporary treatments with Helm." Maxime Guilbert | Sciencx - Monday February 27, 2023, https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/
HARVARD
Maxime Guilbert | Sciencx Monday February 27, 2023 » Execute temporary treatments with Helm., viewed ,<https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/>
VANCOUVER
Maxime Guilbert | Sciencx - » Execute temporary treatments with Helm. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/
CHICAGO
" » Execute temporary treatments with Helm." Maxime Guilbert | Sciencx - Accessed . https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/
IEEE
" » Execute temporary treatments with Helm." Maxime Guilbert | Sciencx [Online]. Available: https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/. [Accessed: ]
rf:citation
» Execute temporary treatments with Helm | Maxime Guilbert | Sciencx | https://www.scien.cx/2023/02/27/execute-temporary-treatments-with-helm/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.