You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Secrets used to populate environment variables by the `envFrom` field that have keys
431
-
that are considered invalid environment variable names will have those keys
432
-
skipped. The Pod is allowed to start.
266
+
If your environment variable definitions in your Pod specification are
267
+
considered to be invalid environment variable names, those keys aren't made
268
+
available to your container. The Pod is allowed to start.
433
269
434
-
If you define a Pod with an invalid variable name, the failed Pod startup includes
435
-
an event with the reason set to `InvalidVariableNames` and a message that lists the
436
-
skipped invalid keys. The following example shows a Pod that refers to a Secret
437
-
named `mysecret`, where `mysecret` contains 2 invalid keys: `1badkey`and `2alsobad`.
270
+
Kubernetes adds an Event with the reason set to `InvalidVariableNames` and a
271
+
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`.
438
272
439
273
```shell
440
274
kubectl get events
@@ -447,42 +281,6 @@ LASTSEEN FIRSTSEEN COUNT NAME KIND SUBOBJECT
447
281
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.
448
282
```
449
283
450
-
451
-
#### Consuming Secret values from environment variables
452
-
453
-
Inside a container that consumes a Secret using environment variables, the secret keys appear
454
-
as normal environment variables. The values of those variables are the base64 decoded values
455
-
of the secret data.
456
-
457
-
This is the result of commands executed inside the container from the example above:
458
-
459
-
```shell
460
-
echo "$SECRET_USERNAME"
461
-
```
462
-
463
-
The output is similar to:
464
-
465
-
```
466
-
admin
467
-
```
468
-
469
-
```shell
470
-
echo "$SECRET_PASSWORD"
471
-
```
472
-
473
-
The output is similar to:
474
-
475
-
```
476
-
1f2d1e2e67df
477
-
```
478
-
479
-
{{< note >}}
480
-
If a container already consumes a Secret in an environment variable,
481
-
a Secret update will not be seen by the container unless it is
482
-
restarted. There are third party solutions for triggering restarts when
If you want to fetch container images from a private repository, you need a way for
@@ -518,43 +316,10 @@ You cannot use ConfigMaps or Secrets with {{< glossary_tooltip text="static Pods
518
316
519
317
## Use cases
520
318
521
-
### Use case: As container environment variables
522
-
523
-
Create a secret
524
-
```yaml
525
-
apiVersion: v1
526
-
kind: Secret
527
-
metadata:
528
-
name: mysecret
529
-
type: Opaque
530
-
data:
531
-
USER_NAME: YWRtaW4=
532
-
PASSWORD: MWYyZDFlMmU2N2Rm
533
-
```
534
-
535
-
Create the Secret:
536
-
```shell
537
-
kubectl apply -f mysecret.yaml
538
-
```
319
+
### Use case: As container environment variables {#use-case-as-container-environment-variables}
539
320
540
-
Use `envFrom` to define all of the Secret's data as container environment variables. The key from
541
-
the Secret becomes the environment variable name in the Pod.
542
-
543
-
```yaml
544
-
apiVersion: v1
545
-
kind: Pod
546
-
metadata:
547
-
name: secret-test-pod
548
-
spec:
549
-
containers:
550
-
- name: test-container
551
-
image: registry.k8s.io/busybox
552
-
command: [ "/bin/sh", "-c", "env" ]
553
-
envFrom:
554
-
- secretRef:
555
-
name: mysecret
556
-
restartPolicy: Never
557
-
```
321
+
You can create a Secret and use it to
322
+
[set environment variables for a container](/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data).
0 commit comments