@@ -146,7 +146,7 @@ is exposed:
146
146
my-app
147
147
39528$vdg7Jb
148
148
` ` `
149
-
149
+
150
150
# # Define container environment variables using Secret data
151
151
152
152
# ## Define a container environment variable with data from a single Secret
@@ -157,40 +157,56 @@ is exposed:
157
157
kubectl create secret generic backend-user --from-literal=backend-username=' backend-admin'
158
158
` ` `
159
159
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
+
162
162
{{< codenew file=" pods/inject/pod-single-secret-env-variable.yaml" > }}
163
-
164
- * Create the Pod:
163
+
164
+ * Create the Pod:
165
165
166
166
` ` ` shell
167
167
kubectl create -f https://k8s.io/examples/pods/inject/pod-single-secret-env-variable.yaml
168
168
` ` `
169
-
170
- * Now, the Pod’s output includes environment variable ` SECRET_USERNAME=backend-admin`
171
169
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
+ ` ` `
172
180
173
181
# ## Define container environment variables with data from multiple Secrets
174
182
175
183
* As with the previous example, create the Secrets first.
176
-
184
+
177
185
` ` ` 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'
181
188
` ` `
182
-
183
- * Define the environment variables in the Pod specification.
184
-
189
+
190
+ * Define the environment variables in the Pod specification.
191
+
185
192
{{< codenew file=" pods/inject/pod-multiple-secret-env-variable.yaml" > }}
186
-
193
+
187
194
* Create the Pod:
188
195
189
196
` ` ` 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
191
209
` ` `
192
-
193
- * Now, the Pod’s output includes ` BACKEND_USERNAME=backend-admin` and ` DB_USERNAME=db-admin` environment variables.
194
210
195
211
196
212
# # 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.
200
216
{{< /note > }}
201
217
202
218
* Create a Secret containing multiple key-value pairs
203
-
219
+
204
220
` ` ` shell
205
221
kubectl create secret generic test-secret --from-literal=username=' my-app' --from-literal=password=' 39528$vdg7Jb'
206
222
` ` `
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.
209
225
210
226
{{< codenew file=" pods/inject/pod-secret-envFrom.yaml" > }}
211
-
227
+
212
228
* Create the Pod:
213
229
214
230
` ` ` shell
215
231
kubectl create -f https://k8s.io/examples/pods/inject/pod-secret-envFrom.yaml
216
232
` ` `
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
+
221
246
{{% /capture %}}
222
247
223
248
{{% capture whatsnext %}}
0 commit comments