github.com/argoproj/argo-cd/v3@v3.2.1/docs/user-guide/helm.md (about)

     1  # Helm
     2  
     3  ## Declarative
     4  
     5  You can install Helm charts through the UI, or in the declarative GitOps way.  
     6  Helm is [only used to inflate charts with `helm template`](../../faq#after-deploying-my-helm-application-with-argo-cd-i-cannot-see-it-with-helm-ls-and-other-helm-commands). The lifecycle of the application is handled by Argo CD instead of Helm.
     7  Here is an example:
     8  
     9  ```yaml
    10  apiVersion: argoproj.io/v1alpha1
    11  kind: Application
    12  metadata:
    13    name: sealed-secrets
    14    namespace: argocd
    15  spec:
    16    project: default
    17    source:
    18      chart: sealed-secrets
    19      repoURL: https://bitnami-labs.github.io/sealed-secrets
    20      targetRevision: 1.16.1
    21      helm:
    22        releaseName: sealed-secrets
    23    destination:
    24      server: "https://kubernetes.default.svc"
    25      namespace: kubeseal
    26  ```
    27  
    28  Another example using a public OCI helm chart:
    29  ```yaml
    30  apiVersion: argoproj.io/v1alpha1
    31  kind: Application
    32  metadata:
    33    name: nginx
    34  spec:
    35    project: default
    36    source:
    37      chart: nginx
    38      repoURL: registry-1.docker.io/bitnamicharts  # note: the oci:// syntax is not included.
    39      targetRevision: 15.9.0
    40    destination:
    41      name: "in-cluster"
    42      namespace: nginx
    43  ```
    44  
    45  !!! note "When using Helm there are multiple ways to provide values"
    46      Order of precedence is `parameters > valuesObject > values > valueFiles > helm repository values.yaml` (see [Here](./helm.md#helm-value-precedence) for a more detailed example)
    47  
    48  See [here](../operator-manual/declarative-setup.md#helm) for more info about how to configure private Helm repositories and private OCI registries.
    49  
    50  ## Values Files
    51  
    52  Helm has the ability to use a different, or even multiple "values.yaml" files to derive its
    53  parameters from. Alternate or multiple values file(s), can be specified using the `--values`
    54  flag. The flag can be repeated to support multiple values files:
    55  
    56  ```bash
    57  argocd app set helm-guestbook --values values-production.yaml
    58  ```
    59  !!! note
    60      Before `v2.6` of Argo CD, Values files must be in the same git repository as the Helm
    61      chart. The files can be in a different location in which case it can be accessed using
    62      a relative path relative to the root directory of the Helm chart.
    63      As of `v2.6`, values files can be sourced from a separate repository than the Helm chart
    64      by taking advantage of [multiple sources for Applications](./multiple_sources.md#helm-value-files-from-external-git-repository).
    65  
    66  In the declarative syntax:
    67  
    68  ```yaml
    69  source:
    70    helm:
    71      valueFiles:
    72      - values-production.yaml
    73  ```
    74  
    75  If Helm is passed a non-existing value file during template expansion, it will error out. Missing
    76  values files can be ignored (meaning, not passed to Helm) using the `--ignore-missing-value-files`. This can be
    77  particularly helpful to implement a [default/override
    78  pattern](https://github.com/argoproj/argo-cd/issues/7767#issue-1060611415) with [Application
    79  Sets](./application-set.md).
    80  
    81  In the declarative syntax:
    82  ```yaml
    83  source:
    84    helm:
    85      valueFiles:
    86      - values-common.yaml
    87      - values-optional-override.yaml
    88      ignoreMissingValueFiles: true
    89  ```
    90  
    91  ## Values
    92  
    93  Argo CD supports the equivalent of a values file directly in the Application manifest using the `source.helm.valuesObject` key.
    94  
    95  ```yaml
    96  source:
    97    helm:
    98      valuesObject:
    99        ingress:
   100          enabled: true
   101          path: /
   102          hosts:
   103            - mydomain.example.com
   104          annotations:
   105            kubernetes.io/ingress.class: nginx
   106            kubernetes.io/tls-acme: "true"
   107          labels: {}
   108          tls:
   109            - secretName: mydomain-tls
   110              hosts:
   111                - mydomain.example.com
   112  ```
   113  
   114  Alternatively, values can be passed in as a string using the `source.helm.values` key.
   115  
   116  ```yaml
   117  source:
   118    helm:
   119      values: |
   120        ingress:
   121          enabled: true
   122          path: /
   123          hosts:
   124            - mydomain.example.com
   125          annotations:
   126            kubernetes.io/ingress.class: nginx
   127            kubernetes.io/tls-acme: "true"
   128          labels: {}
   129          tls:
   130            - secretName: mydomain-tls
   131              hosts:
   132                - mydomain.example.com
   133  ```
   134  
   135  ## Helm Parameters
   136  
   137  Helm has the ability to set parameter values, which override any values in
   138  a `values.yaml`. For example, `service.type` is a common parameter which is exposed in a Helm chart:
   139  
   140  ```bash
   141  helm template . --set service.type=LoadBalancer
   142  ```
   143  
   144  Similarly, Argo CD can override values in the `values.yaml` parameters using `argocd app set` command,
   145  in the form of `-p PARAM=VALUE`. For example:
   146  
   147  ```bash
   148  argocd app set helm-guestbook -p service.type=LoadBalancer
   149  ```
   150  
   151  In the declarative syntax:
   152  
   153  ```yaml
   154  source:
   155    helm:
   156      parameters:
   157      - name: "service.type"
   158        value: LoadBalancer
   159  ```
   160  
   161  ## Helm Value Precedence
   162  Values injections have the following order of precedence
   163   `parameters > valuesObject > values > valueFiles > helm repository values.yaml`
   164   Or rather
   165  
   166  ```
   167      lowest  -> valueFiles
   168              -> values
   169              -> valuesObject
   170      highest -> parameters
   171  ```
   172  
   173  So valuesObject trumps values - therefore values will be ignored, and both valuesObject and values trump valueFiles.
   174  Parameters trump all of them.
   175  
   176  Precedence of multiple valueFiles:
   177  When multiple valueFiles are specified, the last file listed has the highest precedence:
   178  
   179  ```
   180  valueFiles:
   181    - values-file-2.yaml
   182    - values-file-1.yaml
   183  
   184  In this case, values-file-1.yaml will override values from values-file-2.yaml.
   185  ```
   186  
   187  When multiple of the same key are found the last one wins i.e 
   188  
   189  ```
   190  e.g. if we only have values-file-1.yaml and it contains
   191  
   192  param1: value1
   193  param1: value3000
   194  
   195  we get param1=value3000
   196  ```
   197  
   198  ```
   199  parameters:
   200    - name: "param1"
   201      value: value2
   202    - name: "param1"
   203      value: value1
   204  
   205  the result will be param1=value1
   206  ```
   207  
   208  ```
   209  values: |
   210    param1: value2
   211    param1: value5
   212  
   213  the result will be param1=value5
   214  ```
   215  
   216  !!! note "When valueFiles or values is used"
   217      The chart is rendered correctly using the set of values from the different possible sources plus any parameters, merged in the expected order as documented here.
   218      There is a bug (see [this issue](https://github.com/argoproj/argo-cd/issues/9213) in the UI that only shows the parameters, i.e. it does not represent the complete set of values.
   219      As a workaround, using parameters instead of values/valuesObject will provide a better overview of what will be used for resources.
   220  
   221  ## Helm --set-file support
   222  
   223  The `--set-file` argument to helm can be used with the following syntax on
   224  the cli:
   225  
   226  ```bash
   227  argocd app set helm-guestbook --helm-set-file some.key=path/to/file.ext
   228  ```
   229  
   230  or using the fileParameters for yaml:
   231  
   232  ```yaml
   233  source:
   234    helm:
   235      fileParameters:
   236        - name: some.key
   237          path: path/to/file.ext
   238  ```
   239  
   240  ## Helm Release Name
   241  
   242  By default, the Helm release name is equal to the Application name to which it belongs. Sometimes, especially on a centralised Argo CD,
   243  you may want to override that  name, and it is possible with the `release-name` flag on the cli:
   244  
   245  ```bash
   246  argocd app set helm-guestbook --release-name myRelease
   247  ```
   248  
   249   or using the releaseName for yaml:
   250  
   251  ```yaml
   252  source:
   253      helm:
   254        releaseName: myRelease
   255  ```
   256  
   257  !!! warning "Important notice on overriding the release name"
   258      Please note that overriding the Helm release name might cause problems when the chart you are deploying is using the `app.kubernetes.io/instance` label. Argo CD injects this label with the value of the Application name for tracking purposes. So when overriding the release name, the Application name will stop being equal to the release name. Because Argo CD will overwrite the label with the Application name it might cause some selectors on the resources to stop working. In order to avoid this we can configure Argo CD to use another label for tracking in the [ArgoCD configmap argocd-cm.yaml](../operator-manual/argocd-cm.yaml) - check the lines describing `application.instanceLabelKey`.
   259  
   260  ## Helm Hooks
   261  
   262  Helm hooks are similar to [Argo CD hooks](resource_hooks.md). In Helm, a hook
   263  is any normal Kubernetes resource annotated with the `helm.sh/hook` annotation.
   264  
   265  Argo CD supports many (most?) Helm hooks by mapping the Helm annotations onto Argo CD's own hook annotations:
   266  
   267  | Helm Annotation                 | Notes                                                                                         |
   268  | ------------------------------- |-----------------------------------------------------------------------------------------------|
   269  | `helm.sh/hook: crd-install`     | Supported as equivalent to normal Argo CD CRD handling.                                |
   270  | `helm.sh/hook: pre-delete`      | Not supported. In Helm stable there are 3 cases used to clean up CRDs and 3 to clean-up jobs. |
   271  | `helm.sh/hook: pre-rollback`    | Not supported. Never used in Helm stable.                                                     |
   272  | `helm.sh/hook: pre-install`     | Supported as equivalent to `argocd.argoproj.io/hook: PreSync`.                                |
   273  | `helm.sh/hook: pre-upgrade`     | Supported as equivalent to `argocd.argoproj.io/hook: PreSync`.                                |
   274  | `helm.sh/hook: post-upgrade`    | Supported as equivalent to `argocd.argoproj.io/hook: PostSync`.                               |
   275  | `helm.sh/hook: post-install`    | Supported as equivalent to `argocd.argoproj.io/hook: PostSync`.                               |
   276  | `helm.sh/hook: post-delete`     | Supported as equivalent to `argocd.argoproj.io/hook: PostDelete`.                             |
   277  | `helm.sh/hook: post-rollback`   | Not supported. Never used in Helm stable.                                                     |
   278  | `helm.sh/hook: test-success`    | Not supported. No equivalent in Argo CD.                                                      |
   279  | `helm.sh/hook: test-failure`    | Not supported. No equivalent in Argo CD.                                                      |
   280  | `helm.sh/hook-delete-policy`    | Supported. See also `argocd.argoproj.io/hook-delete-policy`).                                 |
   281  | `helm.sh/hook-delete-timeout`   | Not supported. Never used in Helm stable                                                      |
   282  | `helm.sh/hook-weight`           | Supported as equivalent to `argocd.argoproj.io/sync-wave`.                                    |
   283  | `helm.sh/resource-policy: keep` | Supported as equivalent to `argocd.argoproj.io/sync-options: Delete=false`.                   |
   284  
   285  Unsupported hooks are ignored. In Argo CD, hooks are created by using `kubectl apply`, rather than `kubectl create`. This means that if the hook is named and already exists, it will not change unless you have annotated it with `before-hook-creation`.
   286  
   287  !!! warning "Helm hooks + ArgoCD hooks"
   288      If you define any Argo CD hooks, _all_ Helm hooks will be ignored.   
   289  
   290  !!! warning "'install' vs 'upgrade' vs 'sync'"
   291      Argo CD cannot know if it is running a first-time "install" or an "upgrade" - every operation is a "sync'. This means that, by default, apps that have `pre-install` and `pre-upgrade` will have those hooks run at the same time.
   292  
   293  ### Hook Tips
   294  
   295  * Make your hook idempotent.
   296  * Annotate  `pre-install` and `post-install` with `hook-weight: "-1"`. This will make sure it runs to success before any upgrade hooks.
   297  * Annotate `pre-upgrade` and `post-upgrade` with `hook-delete-policy: before-hook-creation` to make sure it runs on every sync.
   298  
   299  Read more about [Argo hooks](resource_hooks.md) and [Helm hooks](https://helm.sh/docs/topics/charts_hooks/).
   300  
   301  ## Random Data
   302  
   303  Helm templating has the ability to generate random data during chart rendering via the
   304  `randAlphaNum` function. Many helm charts from the [charts repository](https://github.com/helm/charts)
   305  make use of this feature. For example, the following is the secret for the
   306  [redis helm chart](https://github.com/helm/charts/blob/master/stable/redis/templates/secret.yaml):
   307  
   308  ```yaml
   309  data:
   310    {{- if .Values.password }}
   311    redis-password: {{ .Values.password | b64enc | quote }}
   312    {{- else }}
   313    redis-password: {{ randAlphaNum 10 | b64enc | quote }}
   314    {{- end }}
   315  ```
   316  
   317  The Argo CD application controller periodically compares Git state against the live state, running
   318  the `helm template <CHART>` command to generate the helm manifests. Because the random value is
   319  regenerated every time the comparison is made, any application which makes use of the `randAlphaNum`
   320  function will always be in an `OutOfSync` state. This can be mitigated by explicitly setting a
   321  value in the values.yaml or using `argocd app set` command to override the value such that the value
   322  is stable between each comparison. For example:
   323  
   324  ```bash
   325  argocd app set redis -p password=abc123
   326  ```
   327  
   328  ## Build Environment
   329  
   330  Helm apps have access to the [standard build environment](build-environment.md) via substitution as parameters.
   331  
   332  E.g. via the CLI:
   333  
   334  ```bash
   335  argocd app create APPNAME \
   336    --helm-set-string 'app=${ARGOCD_APP_NAME}'
   337  ```
   338  
   339  Or via declarative syntax:
   340  
   341  ```yaml
   342    spec:
   343      source:
   344        helm:
   345          parameters:
   346          - name: app
   347            value: $ARGOCD_APP_NAME
   348  ```
   349  
   350  It's also possible to use build environment variables for the Helm values file path:
   351  
   352  ```yaml
   353    spec:
   354      source:
   355        helm:
   356          valueFiles:
   357          - values.yaml
   358          - myprotocol://somepath/$ARGOCD_APP_NAME/$ARGOCD_APP_REVISION
   359  ```
   360  
   361  ## Helm plugins
   362  
   363  Argo CD is un-opinionated on what cloud provider you use and what kind of Helm plugins you are using, that's why there are no plugins delivered with the ArgoCD image.
   364  
   365  But sometimes you want to use a custom plugin. Perhaps you would like to use Google Cloud Storage or Amazon S3 storage to save the Helm charts, for example: https://github.com/hayorov/helm-gcs where you can use `gs://` protocol for Helm chart repository access.
   366  There are two ways to install custom plugins; you can modify the ArgoCD container image, or you can use a Kubernetes `initContainer`.
   367  
   368  ### Modifying the ArgoCD container image
   369  One way to use this plugin is to prepare your own ArgoCD image where it is included.
   370  
   371  Example `Dockerfile`:
   372  
   373  ```dockerfile
   374  FROM argoproj/argocd:v1.5.7
   375  
   376  USER root
   377  RUN apt-get update && \
   378      apt-get install -y \
   379          curl && \
   380      apt-get clean && \
   381      rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
   382  
   383  USER argocd
   384  
   385  ARG GCS_PLUGIN_VERSION="0.3.5"
   386  ARG GCS_PLUGIN_REPO="https://github.com/hayorov/helm-gcs.git"
   387  
   388  RUN helm plugin install ${GCS_PLUGIN_REPO} --version ${GCS_PLUGIN_VERSION}
   389  
   390  ENV HELM_PLUGINS="/home/argocd/.local/share/helm/plugins/"
   391  ```
   392  
   393  The `HELM_PLUGINS` environment property required for ArgoCD to locate plugins correctly.
   394  
   395  Once built, use the custom image for ArgoCD installation.
   396  
   397  ### Using `initContainers`
   398  Another option is to install Helm plugins via Kubernetes `initContainers`.
   399  Some users find this pattern preferable to maintaining their own version of the ArgoCD container image.
   400  
   401  Below is an example of how to add Helm plugins when installing ArgoCD with the [official ArgoCD helm chart](https://github.com/argoproj/argo-helm/tree/master/charts/argo-cd):
   402  
   403  ```yaml
   404  repoServer:
   405    volumes:
   406      - name: gcp-credentials
   407        secret:
   408          secretName: my-gcp-credentials
   409    volumeMounts:
   410      - name: gcp-credentials
   411        mountPath: /gcp
   412    env:
   413      - name: HELM_CACHE_HOME
   414        value: /helm-working-dir
   415      - name: HELM_CONFIG_HOME
   416        value: /helm-working-dir
   417      - name: HELM_DATA_HOME
   418        value: /helm-working-dir
   419    initContainers:
   420      - name: helm-gcp-authentication
   421        image: alpine/helm:3.16.1
   422        volumeMounts:
   423          - name: helm-working-dir
   424            mountPath: /helm-working-dir
   425          - name: gcp-credentials
   426            mountPath: /gcp
   427        env:
   428          - name: HELM_CACHE_HOME
   429            value: /helm-working-dir
   430          - name: HELM_CONFIG_HOME
   431            value: /helm-working-dir
   432          - name: HELM_DATA_HOME
   433            value: /helm-working-dir
   434        command: [ "/bin/sh", "-c" ]
   435        args:
   436          - apk --no-cache add curl;
   437            helm plugin install https://github.com/hayorov/helm-gcs.git;
   438            helm repo add my-gcs-repo gs://my-private-helm-gcs-repository;
   439            chmod -R 777 $HELM_DATA_HOME;
   440  ```
   441  
   442  ## Helm Version
   443  
   444  Argo CD will assume that the Helm chart is v3 (even if the apiVersion field in the chart is Helm v2), unless v2 is explicitly specified within the Argo CD Application (see below).
   445  
   446  If needed, it is possible to specifically set the Helm version to template with by setting the `helm-version` flag on the cli (either v2 or v3):
   447  
   448  ```bash
   449  argocd app set helm-guestbook --helm-version v3
   450  ```
   451  
   452  Or using declarative syntax:
   453  
   454  ```yaml
   455  spec:
   456    source:
   457      helm:
   458        version: v3
   459  ```
   460  
   461  ## Helm `--pass-credentials`
   462  
   463  Helm, [starting with v3.6.1](https://github.com/helm/helm/releases/tag/v3.6.1),
   464  prevents sending repository credentials to download charts that are being served
   465  from a different domain than the repository.
   466  
   467  If needed, it is possible to opt into passing credentials for all domains by setting the `helm-pass-credentials` flag on the cli:
   468  
   469  ```bash
   470  argocd app set helm-guestbook --helm-pass-credentials
   471  ```
   472  
   473  Or using declarative syntax:
   474  
   475  ```yaml
   476  spec:
   477    source:
   478      helm:
   479        passCredentials: true
   480  ```
   481  
   482  ## Helm `--skip-crds`
   483  
   484  Helm installs custom resource definitions in the `crds` folder by default if they are not existing. 
   485  See the [CRD best practices](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/) for details.
   486  
   487  If needed, it is possible to skip the CRD installation step with the `helm-skip-crds` flag on the cli:
   488  
   489  ```bash
   490  argocd app set helm-guestbook --helm-skip-crds
   491  ```
   492  
   493  Or using declarative syntax:
   494  
   495  ```yaml
   496  spec:
   497    source:
   498      helm:
   499        skipCrds: true
   500  ```
   501  
   502  ## Helm `--skip-schema-validation`
   503  
   504  Helm validates the values.yaml file using a values.schema.json file. See [Schema files](https://helm.sh/docs/topics/charts/#schema-files) for details.
   505  
   506  If needed, it is possible to skip the schema validation step with the `helm-skip-schema-validation` flag on the cli:
   507  
   508  ```bash
   509  argocd app set helm-guestbook --helm-skip-schema-validation
   510  ```
   511  
   512  Or using declarative syntax:
   513  
   514  ```yaml
   515  spec:
   516    source:
   517      helm:
   518        skipSchemaValidation: true
   519  ```
   520  
   521  
   522  ## Helm `--skip-tests`
   523  
   524  By default, Helm includes test manifests when rendering templates. Argo CD currently skips manifests that include hooks not supported by Argo CD, including [Helm test hooks](https://helm.sh/docs/topics/chart_tests/). While this feature covers many testing use cases, it is not totally congruent with --skip-tests, so the --skip-tests option can be used.
   525  
   526  If needed, it is possible to skip the test manifests installation step with the `helm-skip-tests` flag on the cli:
   527  
   528  ```bash
   529  argocd app set helm-guestbook --helm-skip-tests
   530  ```
   531  
   532  Or using declarative syntax:
   533  
   534  ```yaml
   535  spec:
   536    source:
   537      helm:
   538        skipTests: true # or false
   539  ```