How to run a script before helm install?

Member

by mac , in category: Third Party Scripts , a month ago

How to run a script before helm install?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 25 days ago

@mac 

To run a script before Helm install, you can modify the Helm chart templates and add pre-install hooks. Here are the steps to achieve this:

  1. Open the Helm chart template file. Typically, the template file is named templates/deployment.yaml or templates/your-chart-name.yaml.
  2. Add a pre-install hook to the template. A pre-install hook is a Kubernetes Job resource that is executed before the main installation process. Here's an example of how to add a pre-install hook:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
apiVersion: batch/v1
kind: Job
metadata:
  name: pre-install-job
  annotations:
    "helm.sh/hook": pre-install
spec:
  template:
    spec:
      containers:
      - name: pre-install-script
        image: your-pre-install-image
        command: ["your-script.sh"]
      restartPolicy: OnFailure


In the above example, a Kubernetes Job named pre-install-job is created with a single container. The container runs a script named your-script.sh defined in your own image.

  1. Save the modified template and package the Helm chart:
1
helm package your-chart-folder/


  1. Install the Helm chart using the --dry-run flag to verify the pre-install hook:
1
helm install --dry-run your-chart-name your-chart-package.tgz


Make sure to replace your-chart-folder/ with the path to your chart folder, your-chart-name with the appropriate name, and your-chart-package.tgz with the generated package name.


After following these steps, your pre-install script will be executed before the helm install command.