How to Run Initialization Scripts on Delegates in Harness NextGen

This document walks you through the steps to follow to Run the Initialization Scripts on Delegates in Harness NextGen.

The Delegate setup files enable you to run startup scripts on the host/container/pod for a Harness Delegate when the Delegate was installed.

You can also add script after the Delegate is installed and then restart the Delegate.

  • INIT_SCRIPT is typically used for Legacy Delegates.

  • INIT_SCRIPT is typically not used for Immutable Delegates. The initialization should be baked into the image for the Immutable Delegate, not executed on startup.

Step 1: Download the Delegate Config File(Delegate YAML)

When you install a Delegate, you are prompted to download its config file. For Kubernetes and Docker Delegates, this is a YAML file.

Download the file and open it in a text editor. Locate the Environment variable INIT_SCRIPT in the StatefulSet .

step 2: Add a Script to the Delegate INIT_SCRIPT Environment Variable

The above-used INIT_SCRIPT is used to Installing Serverless on the K8sDelegate.

Step 3: Install the Delegate

kubectl apply -f harness-delegate.yml

Step 4: Verify the Script

Check the Delegate pod/host/container to see if the script ran correctly.

Step 5: If you want to install the INIT_SCRIPT on an already existing delegate:

  1. Log in to the Kubernetes cluster where your delegate is running.

  2. kubectl get statefulsets -n delegate-namespace get the details of your stateful-sets using this command.

  3. kubectl edit statefulset/statefulset name -n delegate-namespace using this command, you can edit your delegate.yaml and add the required INIT_SCRIPT on an already existing delegate.

  4. Before :

  5. After :

  6. Once you have done the changes check whether pods are recreated using kubectl get pods -n namespace and you are good to use the delegate with serverless deployments.

You can find more information on how to Run Initialization Scripts on Delegates in our documentation here: Run Initialization Scripts on Delegates - Harness Docs

2 Likes