Kustomize

The following configuration options are available for Kustomize:

  • namePrefix is a prefix appended to resources for Kustomize apps
  • nameSuffix is a suffix appended to resources for Kustomize apps
  • images is a list of Kustomize image overrides
  • replicas is a list of Kustomize replica overrides
  • commonLabels is a string map of additional labels
  • forceCommonLabels is a boolean value which defines if it’s allowed to override existing labels
  • commonAnnotations is a string map of additional annotations
  • namespace is a kubernetes resources namespace
  • forceCommonAnnotations is a boolean value which defines if it’s allowed to override existing annotations
  • commonAnnotationsEnvsubst is a boolean value which enables env variables substition in annotation values
  • patches is a list of Kustomize patches that supports inline updates

To use Kustomize with an overlay, point your path to the overlay.

Tip

If you’re generating resources, you should read up how to ignore those generated resources using the IgnoreExtraneous compare option.

Patches

Patches are a way to kustomize resources using inline configurations in Argo CD applications. This allows for kustomizing without kustomization file. patches follow the same logic as the corresponding Kustomization. Any patches that target existing Kustomization file will be merged.

The following Kustomization can be done similarly in an Argo CD application.

  1. apiVersion: kustomize.config.k8s.io/v1beta1
  2. kind: Kustomization
  3. metadata:
  4. name: kustomize-inline-example
  5. namespace: test1
  6. resources:
  7. - https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-deployment.yaml
  8. - https://raw.githubusercontent.com/argoproj/argocd-example-apps/master/guestbook/guestbook-ui-svc.yaml
  9. patches:
  10. - target:
  11. kind: Deployment
  12. name: guestbook-ui
  13. patch: |-
  14. - op: replace
  15. path: /spec/template/spec/containers/0/ports/0/containerPort
  16. value: 443

Application will clone the repository, use the specified path, then kustomize using inline patches configuration.

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: Application
  3. metadata:
  4. name: kustomize-inline-guestbook
  5. namespace: argocd
  6. finalizers:
  7. - resources-finalizer.argocd.argoproj.io
  8. spec:
  9. destination:
  10. namespace: test1
  11. server: https://kubernetes.default.svc
  12. project: default
  13. source:
  14. path: guestbook
  15. repoURL: https://github.com/argoproj/argocd-example-apps.git
  16. targetRevision: master
  17. kustomize:
  18. patches:
  19. - target:
  20. kind: Deployment
  21. name: guestbook-ui
  22. patch: |-
  23. - op: replace
  24. path: /spec/template/spec/containers/0/ports/0/containerPort
  25. value: 443

Private Remote Bases

If you have remote bases that are either (a) HTTPS and need username/password (b) SSH and need SSH private key, then they’ll inherit that from the app’s repo.

This will work if the remote bases uses the same credentials/private key. It will not work if they use different ones. For security reasons your app only ever knows about its own repo (not other team’s or users repos), and so you won’t be able to access other private repos, even if Argo CD knows about them.

Read more about private repos.

kustomize build Options/Parameters

To provide build options to kustomize build of default Kustomize version, use kustomize.buildOptions field of argocd-cm ConfigMap. Use kustomize.buildOptions.<version> to register version specific build options.

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: argocd-cm
  5. namespace: argocd
  6. labels:
  7. app.kubernetes.io/name: argocd-cm
  8. app.kubernetes.io/part-of: argocd
  9. data:
  10. kustomize.buildOptions: --load-restrictor LoadRestrictionsNone
  11. kustomize.buildOptions.v4.4.0: --output /tmp

Custom Kustomize versions

Argo CD supports using multiple Kustomize versions simultaneously and specifies required version per application. To add additional versions make sure required versions are bundled and then use kustomize.path.<version> fields of argocd-cm ConfigMap to register bundled additional versions.

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: argocd-cm
  5. namespace: argocd
  6. labels:
  7. app.kubernetes.io/name: argocd-cm
  8. app.kubernetes.io/part-of: argocd
  9. data:
  10. kustomize.path.v3.5.1: /custom-tools/kustomize_3_5_1
  11. kustomize.path.v3.5.4: /custom-tools/kustomize_3_5_4

Once a new version is configured you can reference it in an Application spec as follows:

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: Application
  3. metadata:
  4. name: guestbook
  5. spec:
  6. source:
  7. repoURL: https://github.com/argoproj/argocd-example-apps.git
  8. targetRevision: HEAD
  9. path: kustomize-guestbook
  10. kustomize:
  11. version: v3.5.4

Additionally, the application kustomize version can be configured using the Parameters tab of the Application Details page, or using the following CLI command:

  1. argocd app set <appName> --kustomize-version v3.5.4

Build Environment

Kustomize apps have access to the standard build environment which can be used in combination with a config managment plugin to alter the rendered manifests.

Kustomizing Helm charts

It’s possible to render Helm charts with Kustomize. Doing so requires that you pass the --enable-helm flag to the kustomize build command. This flag is not part of the Kustomize options within Argo CD. If you would like to render Helm charts through Kustomize in an Argo CD application, you have two options: You can either create a custom plugin, or modify the argocd-cm ConfigMap to include the --enable-helm flag globally for all Kustomize applications:

  1. apiVersion: v1
  2. kind: ConfigMap
  3. metadata:
  4. name: argocd-cm
  5. namespace: argocd
  6. data:
  7. kustomize.buildOptions: --enable-helm

Setting the manifests’ namespace

The spec.destination.namespace field only adds a namespace when it’s missing from the manifests generated by Kustomize. It also uses kubectl to set the namespace, which sometimes misses namespace fields in certain resources (for example, custom resources). In these cases, you might get an error like this: ClusterRoleBinding.rbac.authorization.k8s.io "example" is invalid: subjects[0].namespace: Required value.

Using Kustomize directly to set the missing namespaces can resolve this problem. Setting spec.source.kustomize.namespace instructs Kustomize to set namespace fields to the given value.

If spec.destination.namespace and spec.source.kustomize.namespace are both set, Argo CD will defer to the latter, the namespace value set by Kustomize.