Skip to content

Commit 4ca339f

Browse files
committed
Allow almost all printable ASCII characters in environment variables
1 parent bcb9863 commit 4ca339f

File tree

4 files changed

+61
-17
lines changed

4 files changed

+61
-17
lines changed

content/en/docs/concepts/configuration/configmap.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,42 @@ ConfigMaps consumed as environment variables are not updated automatically and r
205205
A container using a ConfigMap as a [subPath](/docs/concepts/storage/volumes#using-subpath) volume mount will not receive ConfigMap updates.
206206
{{< /note >}}
207207

208+
209+
### Using Configmaps as environment variables
210+
211+
To use a Configmap in an {{< glossary_tooltip text="environment variable" term_id="container-env-variables" >}}
212+
in a Pod:
213+
214+
1. For each container in your Pod specification, add an environment variable
215+
for each Configmap key that you want to use to the
216+
`env[].valueFrom.configMapKeyRef` field.
217+
1. Modify your image and/or command line so that the program looks for values
218+
in the specified environment variables.
219+
220+
This is an example of defining a ConfigMap as a pod environment variable:
221+
```yaml
222+
apiVersion: v1
223+
kind: Pod
224+
metadata:
225+
name: env-configmap
226+
spec:
227+
containers:
228+
- name: envars-test-container
229+
image: nginx
230+
env:
231+
- name: CONFIGMAP_USERNAME
232+
valueFrom:
233+
configMapKeyRef:
234+
name: myconfigmap
235+
key: username
236+
237+
```
238+
239+
#### Invalid environment variables {#restriction-env-from-invalid}
240+
241+
The range of characters allowed for environment variable names in pods is [restricted](/docs/tasks/inject-data-application/
242+
/define-environment-variable-container/#using-environment-variables-inside-of-your-config).
243+
208244
## Immutable ConfigMaps {#configmap-immutable}
209245

210246
{{< feature-state for_k8s_version="v1.21" state="stable" >}}

content/en/docs/concepts/configuration/secret.md

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -566,23 +566,8 @@ For instructions, refer to
566566

567567
#### Invalid environment variables {#restriction-env-from-invalid}
568568

569-
If your environment variable definitions in your Pod specification are
570-
considered to be invalid environment variable names, those keys aren't made
571-
available to your container. The Pod is allowed to start.
572-
573-
Kubernetes adds an Event with the reason set to `InvalidVariableNames` and a
574-
message that lists the skipped invalid keys. The following example shows a Pod that refers to a Secret named `mysecret`, where `mysecret` contains 2 invalid keys: `1badkey` and `2alsobad`.
575-
576-
```shell
577-
kubectl get events
578-
```
579-
580-
The output is similar to:
581-
582-
```
583-
LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT TYPE REASON
584-
0s 0s 1 dapi-test-pod Pod Warning InvalidEnvironmentVariableNames kubelet, 127.0.0.1 Keys [1badkey, 2alsobad] from the EnvFrom secret default/mysecret were skipped since they are considered invalid environment variable names.
585-
```
569+
The range of characters allowed for environment variable names in pods is [restricted](/docs/tasks/inject-data-application/
570+
/define-environment-variable-container/#using-environment-variables-inside-of-your-config).
586571

587572
### Container image pull Secrets {#using-imagepullsecrets}
588573

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: RelaxedEnvironmentVariableValidation
3+
content_type: feature_gate
4+
_build:
5+
list: never
6+
render: false
7+
8+
stages:
9+
- stage: alpha
10+
defaultValue: false
11+
fromVersion: "1.30"
12+
---
13+
Allow almost all printable ASCII characters in environment variables.

content/en/docs/tasks/inject-data-application/define-environment-variable-container.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ The `env` and `envFrom` fields have different effects.
3535
You can read more about [ConfigMap](/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables)
3636
and [Secret](/docs/tasks/inject-data-application/distribute-credentials-secure/#configure-all-key-value-pairs-in-a-secret-as-container-environment-variables).
3737

38+
The character range of the environment variable name can be seen in
39+
[Environment variables names](/docs/concept/configuration/environment/environment-variables-names)
40+
If the `RelaxedEnvironmentVariableValidation` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled,
41+
all [printable ASCII characters](https://www.ascii-code.com/characters/printable-characters) except "=" may be used for environment variable names.
42+
3843
This page explains how to use `env`.
3944

4045
In this exercise, you create a Pod that runs one container. The configuration
@@ -102,6 +107,11 @@ Honorable`, and `Kubernetes`, respectively. The environment variable
102107
`MESSAGE` combines the set of all these environment variables and then uses it
103108
as a CLI argument passed to the `env-print-demo` container.
104109

110+
Environment variable names consist of letters, numbers, underscores,
111+
dots, or hyphens, but the first character cannot be a digit.
112+
If the `RelaxedEnvironmentVariableValidation` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled,
113+
all [printable ASCII characters](https://www.ascii-code.com/characters/printable-characters) except "=" may be used for environment variable names.
114+
105115
```yaml
106116
apiVersion: v1
107117
kind: Pod

0 commit comments

Comments
 (0)