Skip to content

Commit 0c1b3e3

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

File tree

4 files changed

+59
-19
lines changed

4 files changed

+59
-19
lines changed

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

+37
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,43 @@ 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+
It's important to note that the range of characters allowed for environment
240+
variable names in pods is [restricted](/docs/tasks/inject-data-application/
241+
/define-environment-variable-container/#using-environment-variables-inside-of-your-config),
242+
If any keys do not meet the rules, those keys are not made available to your container, though
243+
the Pod is allowed to start.
244+
208245
## Immutable ConfigMaps {#configmap-immutable}
209246

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

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

+4-19
Original file line numberDiff line numberDiff line change
@@ -564,25 +564,10 @@ in a Pod:
564564
For instructions, refer to
565565
[Define container environment variables using Secret data](/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data).
566566

567-
#### Invalid environment variables {#restriction-env-from-invalid}
568-
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-
```
567+
It's important to note that the range of characters allowed for environment variable names in pods is [restricted](/docs/tasks/inject-data-application/
568+
/define-environment-variable-container/#using-environment-variables-inside-of-your-config),
569+
If any keys do not meet the rules, those keys are not made available to your container, though
570+
the Pod is allowed to start.
586571

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

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

+5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ Honorable`, and `Kubernetes`, respectively. The environment variable
102102
`MESSAGE` combines the set of all these environment variables and then uses it
103103
as a CLI argument passed to the `env-print-demo` container.
104104

105+
Environment variable names consist of letters, numbers, underscores,
106+
dots, or hyphens, but the first character cannot be a digit.
107+
If the `RelaxedEnvironmentVariableValidation` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled,
108+
all [printable ASCII characters](https://www.ascii-code.com/characters/printable-characters) except "=" may be used for environment variable names.
109+
105110
```yaml
106111
apiVersion: v1
107112
kind: Pod

0 commit comments

Comments
 (0)