github.com/argoproj/argo-cd/v2@v2.10.9/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  !!! note "When using multiple ways to provide values"
    29      Order of precedence is `parameters > valuesObject > values > valueFiles > helm repository values.yaml` (see [Here](./helm.md#helm-value-precedence) for a more detailed example)
    30  
    31  ## Values Files
    32  
    33  Helm has the ability to use a different, or even multiple "values.yaml" files to derive its
    34  parameters from. Alternate or multiple values file(s), can be specified using the `--values`
    35  flag. The flag can be repeated to support multiple values files:
    36  
    37  ```bash
    38  argocd app set helm-guestbook --values values-production.yaml
    39  ```
    40  !!! note
    41      Before `v2.6` of Argo CD, Values files must be in the same git repository as the Helm
    42      chart. The files can be in a different location in which case it can be accessed using
    43      a relative path relative to the root directory of the Helm chart.
    44      As of `v2.6`, values files can be sourced from a separate repository than the Helm chart
    45      by taking advantage of [multiple sources for Applications](./multiple_sources.md#helm-value-files-from-external-git-repository).
    46  
    47  In the declarative syntax:
    48  
    49  ```yaml
    50  source:
    51    helm:
    52      valueFiles:
    53      - values-production.yaml
    54  ```
    55  
    56  ## Values
    57  
    58  Argo CD supports the equivalent of a values file directly in the Application manifest using the `source.helm.valuesObject` key.
    59  
    60  ```yaml
    61  source:
    62    helm:
    63      valuesObject:
    64        ingress:
    65          enabled: true
    66          path: /
    67          hosts:
    68            - mydomain.example.com
    69          annotations:
    70            kubernetes.io/ingress.class: nginx
    71            kubernetes.io/tls-acme: "true"
    72          labels: {}
    73          tls:
    74            - secretName: mydomain-tls
    75              hosts:
    76                - mydomain.example.com
    77  ```
    78  
    79  Alternatively, values can be passed in as a string using the `source.helm.values` key.
    80  
    81  ```yaml
    82  source:
    83    helm:
    84      values: |
    85        ingress:
    86          enabled: true
    87          path: /
    88          hosts:
    89            - mydomain.example.com
    90          annotations:
    91            kubernetes.io/ingress.class: nginx
    92            kubernetes.io/tls-acme: "true"
    93          labels: {}
    94          tls:
    95            - secretName: mydomain-tls
    96              hosts:
    97                - mydomain.example.com
    98  ```
    99  
   100  ## Helm Parameters
   101  
   102  Helm has the ability to set parameter values, which override any values in
   103  a `values.yaml`. For example, `service.type` is a common parameter which is exposed in a Helm chart:
   104  
   105  ```bash
   106  helm template . --set service.type=LoadBalancer
   107  ```
   108  
   109  Similarly, Argo CD can override values in the `values.yaml` parameters using `argocd app set` command,
   110  in the form of `-p PARAM=VALUE`. For example:
   111  
   112  ```bash
   113  argocd app set helm-guestbook -p service.type=LoadBalancer
   114  ```
   115  
   116  In the declarative syntax:
   117  
   118  ```yaml
   119  source:
   120    helm:
   121      parameters:
   122      - name: "service.type"
   123        value: LoadBalancer
   124  ```
   125  
   126  ## Helm Value Precedence
   127  Values injections have the following order of precedence
   128   `parameters > valuesObject > values > valueFiles > helm repository values.yaml`
   129   Or rather
   130  
   131  ```
   132      lowest  -> valueFiles
   133              -> values
   134              -> valuesObject
   135      highest -> parameters
   136  ```
   137  
   138  so values/valuesObject trumps valueFiles, and parameters trump both.
   139  
   140  Precedence of valueFiles themselves is the order they are defined in
   141  
   142  ```
   143  if we have
   144  
   145  valuesFile:
   146    - values-file-2.yaml
   147    - values-file-1.yaml
   148  
   149  the last values-file i.e. values-file-1.yaml will trump the first
   150  ```
   151  
   152  When multiple of the same key are found the last one wins i.e 
   153  
   154  ```
   155  e.g. if we only have values-file-1.yaml and it contains
   156  
   157  param1: value1
   158  param1: value3000
   159  
   160  we get param1=value3000
   161  ```
   162  
   163  ```
   164  parameters:
   165    - name: "param1"
   166      value: value2
   167    - name: "param1"
   168      value: value1
   169  
   170  the result will be param1=value1
   171  ```
   172  
   173  ```
   174  values: |
   175    param1: value2
   176    param1: value5
   177  
   178  the result will be param1=value5
   179  ```
   180  
   181  !!! note "When valuesFiles or values is used"
   182      The list of parameters seen in the ui is not what is used for resources, rather it is the values/valuesObject merged with parameters (see [this issue](https://github.com/argoproj/argo-cd/issues/9213) incase it has been resolved)
   183      As a workaround using parameters instead of values/valuesObject will provide a better overview of what will be used for resources
   184  
   185  ## Helm Release Name
   186  
   187  By default, the Helm release name is equal to the Application name to which it belongs. Sometimes, especially on a centralised Argo CD,
   188  you may want to override that  name, and it is possible with the `release-name` flag on the cli:
   189  
   190  ```bash
   191  argocd app set helm-guestbook --release-name myRelease
   192  ```
   193  
   194   or using the releaseName for yaml:
   195  
   196  ```yaml
   197  source:
   198      helm:
   199        releaseName: myRelease
   200  ```
   201  
   202  !!! warning "Important notice on overriding the release name"
   203      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`.
   204  
   205  ## Helm Hooks
   206  
   207  Helm hooks are similar to [Argo CD hooks](resource_hooks.md). In Helm, a hook
   208  is any normal Kubernetes resource annotated with the `helm.sh/hook` annotation.
   209  
   210  Argo CD supports many (most?) Helm hooks by mapping the Helm annotations onto Argo CD's own hook annotations:
   211  
   212  | Helm Annotation                 | Notes                                                                                         |
   213  | ------------------------------- |-----------------------------------------------------------------------------------------------|
   214  | `helm.sh/hook: crd-install`     | Supported as equivalent to `argocd.argoproj.io/hook: PreSync`.                                |
   215  | `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. |
   216  | `helm.sh/hook: pre-rollback`    | Not supported. Never used in Helm stable.                                                     |
   217  | `helm.sh/hook: pre-install`     | Supported as equivalent to `argocd.argoproj.io/hook: PreSync`.                                |
   218  | `helm.sh/hook: pre-upgrade`     | Supported as equivalent to `argocd.argoproj.io/hook: PreSync`.                                |
   219  | `helm.sh/hook: post-upgrade`    | Supported as equivalent to `argocd.argoproj.io/hook: PostSync`.                               |
   220  | `helm.sh/hook: post-install`    | Supported as equivalent to `argocd.argoproj.io/hook: PostSync`.                               |
   221  | `helm.sh/hook: post-delete`     | Supported as equivalent to `argocd.argoproj.io/hook: PostDelete`.                             |
   222  | `helm.sh/hook: post-rollback`   | Not supported. Never used in Helm stable.                                                     |
   223  | `helm.sh/hook: test-success`    | Not supported. No equivalent in Argo CD.                                                      |
   224  | `helm.sh/hook: test-failure`    | Not supported. No equivalent in Argo CD.                                                      |
   225  | `helm.sh/hook-delete-policy`    | Supported. See also `argocd.argoproj.io/hook-delete-policy`).                                 |
   226  | `helm.sh/hook-delete-timeout`   | Not supported. Never used in Helm stable                                                      |
   227  | `helm.sh/hook-weight`           | Supported as equivalent to `argocd.argoproj.io/sync-wave`.                                    |
   228  | `helm.sh/resource-policy: keep` | Supported as equivalent to `argocd.argoproj.io/sync-options: Delete=false`.                   |
   229  
   230  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`.
   231  
   232  !!! warning "Helm hooks + ArgoCD hooks"
   233      If you define any Argo CD hooks, _all_ Helm hooks will be ignored.   
   234  
   235  !!! warning "'install' vs 'upgrade' vs 'sync'"
   236      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.
   237  
   238  ### Hook Tips
   239  
   240  * Make your hook idempotent.
   241  * Annotate `crd-install` with `hook-weight: "-2"` to make sure it runs to success before any install or upgrade hooks.
   242  * Annotate  `pre-install` and `post-install` with `hook-weight: "-1"`. This will make sure it runs to success before any upgrade hooks.
   243  * Annotate `pre-upgrade` and `post-upgrade` with `hook-delete-policy: before-hook-creation` to make sure it runs on every sync.
   244  
   245  Read more about [Argo hooks](resource_hooks.md) and [Helm hooks](https://helm.sh/docs/topics/charts_hooks/).
   246  
   247  ## Random Data
   248  
   249  Helm templating has the ability to generate random data during chart rendering via the
   250  `randAlphaNum` function. Many helm charts from the [charts repository](https://github.com/helm/charts)
   251  make use of this feature. For example, the following is the secret for the
   252  [redis helm chart](https://github.com/helm/charts/blob/master/stable/redis/templates/secret.yaml):
   253  
   254  ```yaml
   255  data:
   256    {{- if .Values.password }}
   257    redis-password: {{ .Values.password | b64enc | quote }}
   258    {{- else }}
   259    redis-password: {{ randAlphaNum 10 | b64enc | quote }}
   260    {{- end }}
   261  ```
   262  
   263  The Argo CD application controller periodically compares Git state against the live state, running
   264  the `helm template <CHART>` command to generate the helm manifests. Because the random value is
   265  regenerated every time the comparison is made, any application which makes use of the `randAlphaNum`
   266  function will always be in an `OutOfSync` state. This can be mitigated by explicitly setting a
   267  value in the values.yaml or using `argocd app set` command to overide the value such that the value
   268  is stable between each comparison. For example:
   269  
   270  ```bash
   271  argocd app set redis -p password=abc123
   272  ```
   273  
   274  ## Build Environment
   275  
   276  Helm apps have access to the [standard build environment](build-environment.md) via substitution as parameters.
   277  
   278  E.g. via the CLI:
   279  
   280  ```bash
   281  argocd app create APPNAME \
   282    --helm-set-string 'app=${ARGOCD_APP_NAME}'
   283  ```
   284  
   285  Or via declarative syntax:
   286  
   287  ```yaml
   288    spec:
   289      source:
   290        helm:
   291          parameters:
   292          - name: app
   293            value: $ARGOCD_APP_NAME
   294  ```
   295  
   296  It's also possible to use build environment variables for the Helm values file path:
   297  
   298  ```yaml
   299    spec:
   300      source:
   301        helm:
   302          valueFiles:
   303          - values.yaml
   304          - myprotocol://somepath/$ARGOCD_APP_NAME/$ARGOCD_APP_REVISION
   305  ```
   306  
   307  ## Helm plugins
   308  
   309  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.
   310  
   311  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.
   312  There are two ways to install custom plugins; you can modify the ArgoCD container image, or you can use a Kubernetes `initContainer`.
   313  
   314  ### Modifying the ArgoCD container image
   315  One way to use this plugin is to prepare your own ArgoCD image where it is included.
   316  
   317  Example `Dockerfile`:
   318  
   319  ```dockerfile
   320  FROM argoproj/argocd:v1.5.7
   321  
   322  USER root
   323  RUN apt-get update && \
   324      apt-get install -y \
   325          curl && \
   326      apt-get clean && \
   327      rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
   328  
   329  USER argocd
   330  
   331  ARG GCS_PLUGIN_VERSION="0.3.5"
   332  ARG GCS_PLUGIN_REPO="https://github.com/hayorov/helm-gcs.git"
   333  
   334  RUN helm plugin install ${GCS_PLUGIN_REPO} --version ${GCS_PLUGIN_VERSION}
   335  
   336  ENV HELM_PLUGINS="/home/argocd/.local/share/helm/plugins/"
   337  ```
   338  
   339  You have to remember about `HELM_PLUGINS` environment property - this is required for plugins to work correctly.
   340  
   341  After that you have to use your custom image for ArgoCD installation.
   342  
   343  ### Using `initContainers`
   344  Another option is to install Helm plugins via Kubernetes `initContainers`.
   345  Some users find this pattern preferable to maintaining their own version of the ArgoCD container image.
   346  
   347  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):
   348  
   349  ```yaml
   350  repoServer:
   351    volumes:
   352      - name: gcp-credentials
   353        secret:
   354          secretName: my-gcp-credentials
   355    volumeMounts:
   356      - name: gcp-credentials
   357        mountPath: /gcp
   358    env:
   359      - name: HELM_CACHE_HOME
   360        value: /helm-working-dir
   361      - name: HELM_CONFIG_HOME
   362        value: /helm-working-dir
   363      - name: HELM_DATA_HOME
   364        value: /helm-working-dir
   365    initContainers:
   366      - name: helm-gcp-authentication
   367        image: alpine/helm:3.8.1
   368        volumeMounts:
   369          - name: helm-working-dir
   370            mountPath: /helm-working-dir
   371          - name: gcp-credentials
   372            mountPath: /gcp
   373        env:
   374          - name: HELM_CACHE_HOME
   375            value: /helm-working-dir
   376          - name: HELM_CONFIG_HOME
   377            value: /helm-working-dir
   378          - name: HELM_DATA_HOME
   379            value: /helm-working-dir
   380        command: [ "/bin/sh", "-c" ]
   381        args:
   382          - apk --no-cache add curl;
   383            helm plugin install https://github.com/hayorov/helm-gcs.git;
   384            helm repo add my-gcs-repo gs://my-private-helm-gcs-repository;
   385            chmod -R 777 $HELM_DATA_HOME;
   386  ```
   387  
   388  ## Helm Version
   389  
   390  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).
   391  
   392  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):
   393  
   394  ```bash
   395  argocd app set helm-guestbook --helm-version v3
   396  ```
   397  
   398  Or using declarative syntax:
   399  
   400  ```yaml
   401  spec:
   402    source:
   403      helm:
   404        version: v3
   405  ```
   406  
   407  ## Helm `--pass-credentials`
   408  
   409  Helm, [starting with v3.6.1](https://github.com/helm/helm/releases/tag/v3.6.1),
   410  prevents sending repository credentials to download charts that are being served
   411  from a different domain than the repository.
   412  
   413  If needed, it is possible to opt into passing credentials for all domains by setting the `helm-pass-credentials` flag on the cli:
   414  
   415  ```bash
   416  argocd app set helm-guestbook --helm-pass-credentials
   417  ```
   418  
   419  Or using declarative syntax:
   420  
   421  ```yaml
   422  spec:
   423    source:
   424      helm:
   425        passCredentials: true
   426  ```
   427  
   428  ## Helm `--skip-crds`
   429  
   430  Helm installs custom resource definitions in the `crds` folder by default if they are not existing. 
   431  See the [CRD best practices](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/) for details.
   432  
   433  If needed, it is possible to skip the CRD installation step with the `helm-skip-crds` flag on the cli:
   434  
   435  ```bash
   436  argocd app set helm-guestbook --helm-skip-crds
   437  ```
   438  
   439  Or using declarative syntax:
   440  
   441  ```yaml
   442  spec:
   443    source:
   444      helm:
   445        skipCrds: true
   446  ```