> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/cd-kubernetes-category/service-hooks.md).

# Service Hooks

Kubernetes and Helm deployments use service hooks to fetch Helm Chart dependencies that refer to Git and other repositories, and install them with the main Helm Chart.

Harness supports two types of service hooks: preHook and postHook. These are the service hook actions supported by Harness:

* Fetch files: Service hooks can be triggered before or after the manifest files are fetched.
* Manifest templates: Service hooks can be triggered before or after the manifest has been rendered.
* Steady state check: Service hooks can be triggered before or after the steady state check.

Each service hook has its own context variable:

| **Action**         | **Context Variable and Description**                                                                                                                                                                                                                              |
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Fetch files        | `$MANIFEST_FILES_DIRECTORY`: The path to the directory from where the manifest files can be downloaded.                                                                                                                                                           |
| Manifest template  | `$MANIFEST_FILES_DIRECTORY`: The path to the directory where the original Kubernetes template is located.                                                                                                                                                         |
| Steady state check | <p><code>$WORKLOADS\_LIST</code>: The comma separated list of all workloads.<br><code>$MANAGED\_WORKLOADS</code>: The comma separated list of workloads managed by Harness.<br><code>$CUSTOM\_WORKLOADS</code>: The comma separated list of custom workloads.</p> |

#### Native Helm: values overrides and SOPS <a href="#native-helm-values-overrides-and-sops" id="native-helm-values-overrides-and-sops"></a>

For **Native Helm** services, when the feature flag `CDS_HELM_IMPROVED_SOPS_SUPPORT_FOR_SERVICE_HOOKS` is enabled, Harness exposes additional context for decrypting or generating Helm values overrides in **Fetch files** post-hooks:

* **`VALUES_OVERRIDE_DIRECTORY`:** Directory where Harness writes Harness-defined override YAML files (`override-0.yaml`, `override-1.yaml`, …) before your post-hook runs.
* **`OVERRIDE_FILES`:** Export this environment variable from your hook with a comma-separated list of extra override file paths for Helm to use after the hook completes.

You can still use `$MANIFEST_FILES_DIRECTORY` for chart files; Harness-defined overrides are also available under `$MANIFEST_FILES_DIRECTORY/values-overrides` when that path applies to your deployment.

For prerequisites, delegate version, and examples, go to [SOPS and values overrides in Native Helm service hooks](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/helm/native-helm-sops-overrides-service-hooks.md).

You can use service hooks to run additional configurations when carrying out the actions above. For example, when you run a deployment, you must fetch files first. After fetching the files, you can resolve the secrets of those encrypted files using Helm secrets, SOPS, AGE keys, and so on. You can use the context variables above during deployment. For more details, go to [Using shell scripts in CD stages](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/utilities/shell-script-step.md).

Here are some sample service hook YAMLs:

```
hooks:
  - preHook:
      identifier: sample
      storeType: Inline
      actions:
        - FetchFiles
        - TemplateManifest
        - SteadyStateCheck
      store:
        content: echo "sample Hook for all action"
```

```
hooks:
  - postHook:
      identifier: dependency
      storeType: Inline
      actions:
        - FetchFiles
      store:
        content: |
          cd $MANIFEST_FILES_DIRECTORY
          helm repo add test-art-remote https://sample.jfrog.io/artifactory/sample-charts/ --username automationuser --password <+secrets.getValue("reposecret")>
          helm dependency build
          cd charts
```

```
hooks:
  - postHook:
      identifier: cdasd
      storeType: Inline
      actions:
        - FetchFiles
      store:
        content: |-
          source $HOME/.profile
          cd $MANIFEST_FILES_DIRECTORY
          echo $MANIFEST_FILES_DIRECTORY
          export SOPS_AGE_KEY=<+secrets.getValue("agesecret")>
          helm secrets decrypt secrets.enc.yaml
          helm secrets decrypt secrets.enc.yaml > secrets.yaml
```

For more information about Helm dependencies, go to [Helm dependency](https://helm.sh/docs/helm/helm_dependency/) and [Helm dependency update](https://helm.sh/docs/helm/helm_dependency_update/).

{% hint style="warning" %}
Harness does not support **Helm hooks** for Helm **Blue-Green** and **Canary** deployments.
{% endhint %}
