This is an Exec KRM function for Kustomize. It applies envsubst as per this package: https://github.com/drone/envsubst on the configuration files
Build from source:
go install github.com/logandavies181/kustomize-krm-envsubst@latest
Or check out releases
Install this binary as above.
Add a transformer to your kustomize configuration
# kustomization.yaml
resources:
- secret.yaml
transformers:
- transformer.yaml
# transformer.yaml
apiVersion: kustomize-krm-envsubst/v1alpha
kind: Envsubst
metadata:
name: envsubst
annotations:
config.kubernetes.io/function: |
exec:
# ~ is not expanded by kustomize :(
path: /path/to/kustomize-krm-envsubst
#excludedVariableNames: [] # used to denylist certain env var names from being injected
#includedVariableNames: [] # used to enumerate the list of env var names to inject
#ignoredKeys: [] # used to exclude parts of the input from processing
# for example if you're passing a script in a configmap
#values: # explicit keys and values to inject
# FOO: baz
# BAR: zar
Inject environment variables into your manifests!
# secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: super-secret-value
# always use stringData for using this plugin with secrets
stringData:
password: ${PASSWORD}
Render your configuration
# Can only be run in this mode with `kustomize build` and not `kubectl kustomize`
# see https://github.com/kubernetes-sigs/kustomize/issues/4556#issuecomment-1092095023
kustomize build --enable-alpha-plugins --enable-exec .
Use this method to use this plugin with kubectl kustomize
Install the binary to
${XDG_CONFIG_HOME:-~/.config}/kustomize/plugin/kustomize-krm-envsubst/v1alpha/kustomize-krm-envsubst/kustomize-krm-envsubst
Set up your kustomization.yaml and other files as above but use this config for transformer.yaml:
# transformer.yaml
apiVersion: kustomize-krm-envsubst/v1alpha
kind: Envsubst
metadata:
name: envsubst
#excludedVariableNames: [] # used to denylist certain env var names from being injected
#includedVariableNames: [] # used to enumerate the list of env var names to inject
#ignoredKeys: [] # used to exclude parts of the input from processing
# for example if you're passing a script in a configmap
#values: # explicit keys and values to inject
# FOO: baz
# BAR: zar