Skip to content

Commit ba83ccc

Browse files
authored
Merge pull request #21027 from scoulomb/secTask
Improve task 'Distribute Credentials Securely Using Secrets' by showi…
2 parents 7b05e98 + 224a6ca commit ba83ccc

File tree

1 file changed

+51
-26
lines changed

1 file changed

+51
-26
lines changed

content/en/docs/tasks/inject-data-application/distribute-credentials-secure.md

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ is exposed:
146146
my-app
147147
39528$vdg7Jb
148148
```
149-
149+
150150
## Define container environment variables using Secret data
151151

152152
### Define a container environment variable with data from a single Secret
@@ -157,40 +157,56 @@ is exposed:
157157
kubectl create secret generic backend-user --from-literal=backend-username='backend-admin'
158158
```
159159

160-
* Assign the `backend-username` value defined in the Secret to the `SECRET_USERNAME` environment variable in the Pod specification.
161-
160+
* Assign the `backend-username` value defined in the Secret to the `SECRET_USERNAME` environment variable in the Pod specification.
161+
162162
{{< codenew file="pods/inject/pod-single-secret-env-variable.yaml" >}}
163-
164-
* Create the Pod:
163+
164+
* Create the Pod:
165165

166166
```shell
167167
kubectl create -f https://k8s.io/examples/pods/inject/pod-single-secret-env-variable.yaml
168168
```
169-
170-
* Now, the Pod’s output includes environment variable `SECRET_USERNAME=backend-admin`
171169

170+
* In your shell, display the content of `SECRET_USERNAME` container environment variable
171+
172+
```shell
173+
kubectl exec -it env-single-secret -- /bin/sh -c 'echo $SECRET_USERNAME'
174+
```
175+
176+
The output is
177+
```shell
178+
backend-admin
179+
```
172180

173181
### Define container environment variables with data from multiple Secrets
174182

175183
* As with the previous example, create the Secrets first.
176-
184+
177185
```shell
178-
kubectl create secret generic backend-user --from-literal=backend-username='backend-admin'
179-
180-
kubectl create secret generic db-user --from-literal=db-username='db-admin'
186+
kubectl create secret generic backend-user --from-literal=backend-username='backend-admin'
187+
kubectl create secret generic db-user --from-literal=db-username='db-admin'
181188
```
182-
183-
* Define the environment variables in the Pod specification.
184-
189+
190+
* Define the environment variables in the Pod specification.
191+
185192
{{< codenew file="pods/inject/pod-multiple-secret-env-variable.yaml" >}}
186-
193+
187194
* Create the Pod:
188195

189196
```shell
190-
kubectl create -f https://k8s.io/examples/pods/inject/pod-multiple-secret-env-variable.yaml
197+
kubectl create -f https://k8s.io/examples/pods/inject/pod-multiple-secret-env-variable.yaml
198+
```
199+
200+
* In your shell, display the container environment variables
201+
202+
```shell
203+
kubectl exec -it envvars-multiple-secrets -- /bin/sh -c 'env | grep _USERNAME'
204+
```
205+
The output is
206+
```shell
207+
DB_USERNAME=db-admin
208+
BACKEND_USERNAME=backend-admin
191209
```
192-
193-
* Now, the Pod’s output includes `BACKEND_USERNAME=backend-admin` and `DB_USERNAME=db-admin` environment variables.
194210

195211

196212
## Configure all key-value pairs in a Secret as container environment variables
@@ -200,24 +216,33 @@ This functionality is available in Kubernetes v1.6 and later.
200216
{{< /note >}}
201217

202218
* Create a Secret containing multiple key-value pairs
203-
219+
204220
```shell
205221
kubectl create secret generic test-secret --from-literal=username='my-app' --from-literal=password='39528$vdg7Jb'
206222
```
207-
208-
* Use envFrom to define all of the Secret’s data as container environment variables. The key from the Secret becomes the environment variable name in the Pod.
223+
224+
* Use envFrom to define all of the Secret’s data as container environment variables. The key from the Secret becomes the environment variable name in the Pod.
209225

210226
{{< codenew file="pods/inject/pod-secret-envFrom.yaml" >}}
211-
227+
212228
* Create the Pod:
213229

214230
```shell
215231
kubectl create -f https://k8s.io/examples/pods/inject/pod-secret-envFrom.yaml
216232
```
217-
218-
* Now, the Pod’s output includes `username=my-app` and `password=39528$vdg7Jb` environment variables.
219-
220-
233+
234+
* In your shell, display `username` and `password` container environment variables
235+
236+
````shell
237+
kubectl exec -it envfrom-secret -- /bin/sh -c 'echo "username: $username\npassword: $password"'
238+
````
239+
240+
The output is
241+
````shell
242+
username: my-app
243+
password: 39528$vdg7Jb
244+
````
245+
221246
{{% /capture %}}
222247

223248
{{% capture whatsnext %}}

0 commit comments

Comments
 (0)