Update secret.md

pull/20439/head
Alpha 2020-04-19 19:54:06 +08:00 committed by alpha.wong
parent 7b637bdb06
commit a0f9db9382
1 changed files with 37 additions and 0 deletions

View File

@ -854,6 +854,43 @@ start until all the Pod's volumes are mounted.
## Use cases
### Use-Case: As container environment variables
Create a secret
```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
USER_NAME: YWRtaW4=
PASSWORD: MWYyZDFlMmU2N2Rm
```
Create the Secret:
```shell
kubectl apply -f mysecret.yaml
```
Use `envFrom` to define all of the Secrets data as container environment variables. The key from the Secret becomes the environment variable name in the Pod.
```yaml
apiVersion: v1
kind: Pod
metadata:
name: secret-test-pod
spec:
containers:
- name: test-container
image: k8s.gcr.io/busybox
command: [ "/bin/sh", "-c", "env" ]
envFrom:
- secretRef:
name: mysecret
restartPolicy: Never
```
### Use-Case: Pod with ssh keys
Create a secret containing some ssh keys: