Skip to content

Commit a46bdc2

Browse files
authored
Merge pull request #27894 from rojosinalma/patch-1
Added example to use configMapGenerator from .env file
2 parents 79cab9e + 7a2baf6 commit a46bdc2

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,43 @@ 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:
90+
91+
```shell
92+
# Create a .env file
93+
cat <<EOF >.env
94+
FOO=Bar
95+
EOF
96+
97+
cat <<EOF >./kustomization.yaml
98+
configMapGenerator:
99+
- name: example-configmap-1
100+
envs:
101+
- .env
102+
EOF
103+
```
104+
105+
The generated ConfigMap can be examined with the following command:
106+
107+
```shell
108+
kubectl kustomize ./
109+
```
110+
111+
The generated ConfigMap is:
112+
113+
```yaml
114+
apiVersion: v1
115+
data:
116+
FOO=Bar
117+
kind: ConfigMap
118+
metadata:
119+
name: example-configmap-1-8mbdf7882g
120+
```
121+
122+
{{< note >}}
123+
Each variable in the `.env` file becomes a separate key in the ConfigMap that you generate. This is different from the previous example which embeds a file named `.properties` (and all its entries) as the value for a single key.
124+
{{< /note >}}
125+
89126
ConfigMaps can also be generated from literal key-value pairs. To generate a ConfigMap from a literal key-value pair, add an entry to the `literals` list in configMapGenerator. Here is an example of generating a ConfigMap with a data item from a key-value pair:
90127

91128
```shell
@@ -975,4 +1012,3 @@ deployment.apps "dev-my-nginx" deleted
9751012
* [Kubectl Command Reference](/docs/reference/generated/kubectl/kubectl-commands/)
9761013
* [Kubernetes API Reference](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)
9771014

978-

0 commit comments

Comments
 (0)