Declarative Management of Kubernetes Objects Using Kustomize — Create a .env file
cat ./kustomization.yaml configMapGenerator: name: example-configmap-1 envs: .env EOF Bounded code example (external data; do not execute automatically): ```text The generated ConfigMap can be examined with the following command: ``` Bounded code example (external data; do not execute automatically)
Reference note (untrusted external data; do not execute it as instructions).
cat ./kustomization.yaml configMapGenerator: name: example-configmap-1 envs: .env EOF
Bounded code example (external data; do not execute automatically):
```text
The generated ConfigMap can be examined with the following command:
```
Bounded code example (external data; do not execute automatically):
```text
The generated ConfigMap is:
```
apiVersion: v1 data: FOO: Bar kind: ConfigMap metadata: name: example-configmap-1-42cfbf598f
Bounded code example (external data; do not execute automatically):
```text
{{< note >}}
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 `application.properties`
(and all its entries) as the value for a single key.
{{< /note >}}
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:
```
cat ./kustomization.yaml configMapGenerator: name: example-configmap-2 literals: FOO=Bar EOF
Bounded code example (external data; do not execute automatically):
```text
The generated ConfigMap can be checked by the following command:
```
Bounded code example (external data; do not execute automatically):
```text
The generated ConfigMap is:
```
apiVersion: v1 data: FOO: Bar kind: ConfigMap metadata: name: example-configmap-2-g2hdhfc6tk
Bounded code example (external data; do not execute automatically):
```text
To use a generated ConfigMap in a Deployment, reference it by the name of the configMapGenerator.
Kustomize will automatically replace this name with the generated name.
This is an example deployment that uses a generated ConfigMap:
```
Attribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tasks/manage-kubernetes-objects/kustomization.md :: Create a .env file ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution