Skip to content

Commit b9da040

Browse files
committed
Document the environment variable substitution feature of configMapGenerator
1 parent 63dd5f7 commit b9da040

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

content/en/docs/tasks/manage-kubernetes-objects/kustomization.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ metadata:
8686
name: example-configmap-1-8mbdf7882g
8787
```
8888
89-
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:
89+
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.
90+
91+
{{< note >}}
92+
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.
93+
{{< /note >}}
94+
95+
Here is an example of generating a ConfigMap with a data item from a `.env` file:
9096

9197
```shell
9298
# Create a .env file
99+
# BAZ will be populated from the local environment variable $BAZ
93100
cat <<EOF >.env
94101
FOO=Bar
102+
BAZ
95103
EOF
96104
97105
cat <<EOF >./kustomization.yaml
@@ -105,18 +113,19 @@ EOF
105113
The generated ConfigMap can be examined with the following command:
106114

107115
```shell
108-
kubectl kustomize ./
116+
BAZ=Qux kubectl kustomize ./
109117
```
110118

111119
The generated ConfigMap is:
112120

113121
```yaml
114122
apiVersion: v1
115123
data:
124+
BAZ: Qux
116125
FOO: Bar
117126
kind: ConfigMap
118127
metadata:
119-
name: example-configmap-1-42cfbf598f
128+
name: example-configmap-1-892ghb99c8
120129
```
121130

122131
{{< note >}}

0 commit comments

Comments
 (0)