Document the environment variable substitution feature of configMapGenerator

This commit is contained in:
afirth
2021-11-03 16:14:32 +01:00
parent 63dd5f7a00
commit b9da040a08
@@ -86,12 +86,20 @@ metadata:
name: example-configmap-1-8mbdf7882g name: example-configmap-1-8mbdf7882g
``` ```
To generate a ConfigMap from an env file, add an entry to the `envs` list in `configMapGenerator`. Here is an example of generating a ConfigMap with a data item from a `.env` file: To generate a ConfigMap from an env file, add an entry to the `envs` list in `configMapGenerator`. This can also be used to set values from local environment variables by omitting the `=` and the value.
{{< note >}}
It's recommended to use the local environment variable population functionality sparingly - an overlay with a patch is often more maintainable. Setting values from the environment may be useful when they cannot easily be predicted, such as a git SHA.
{{< /note >}}
Here is an example of generating a ConfigMap with a data item from a `.env` file:
```shell ```shell
# Create a .env file # Create a .env file
# BAZ will be populated from the local environment variable $BAZ
cat <<EOF >.env cat <<EOF >.env
FOO=Bar FOO=Bar
BAZ
EOF EOF
cat <<EOF >./kustomization.yaml cat <<EOF >./kustomization.yaml
@@ -105,7 +113,7 @@ EOF
The generated ConfigMap can be examined with the following command: The generated ConfigMap can be examined with the following command:
```shell ```shell
kubectl kustomize ./ BAZ=Qux kubectl kustomize ./
``` ```
The generated ConfigMap is: The generated ConfigMap is:
@@ -113,10 +121,11 @@ The generated ConfigMap is:
```yaml ```yaml
apiVersion: v1 apiVersion: v1
data: data:
BAZ: Qux
FOO: Bar FOO: Bar
kind: ConfigMap kind: ConfigMap
metadata: metadata:
name: example-configmap-1-42cfbf598f name: example-configmap-1-892ghb99c8
``` ```
{{< note >}} {{< note >}}