@@ -12,8 +12,10 @@ encryption keys, into Pods.
12
12
-->
13
13
本文展示如何安全地将敏感数据(如密码和加密密钥)注入到 Pods 中。
14
14
15
+
15
16
## {{% heading "prerequisites" %}}
16
17
18
+
17
19
{{< include "task-tutorial-prereqs.md" >}}
18
20
19
21
@@ -69,8 +71,10 @@ username and password:
69
71
kubectl apply -f https://k8s.io/examples/pods/inject/secret.yaml
70
72
```
71
73
72
- 1 . <!-- View information about the Secret -->
73
- 查看 Secret 相关信息:
74
+ <!--
75
+ 1. View information about the Secret:
76
+ -->
77
+ 2 . 查看 Secret 相关信息:
74
78
75
79
``` shell
76
80
kubectl get secret test-secret
@@ -79,12 +83,12 @@ username and password:
79
83
<!-- Output: -->
80
84
输出:
81
85
82
- ``` shell
86
+ ```
83
87
NAME TYPE DATA AGE
84
88
test-secret Opaque 2 1m
85
89
```
86
90
87
- 1 . <!-- View more detailed information about the Secret -->
91
+ 1 . <!-- View more detailed information about the Secret: -->
88
92
查看 Secret 相关的更多详细信息:
89
93
90
94
``` shell
@@ -94,7 +98,7 @@ username and password:
94
98
<!-- Output: -->
95
99
输出:
96
100
97
- ``` shell
101
+ ```
98
102
Name: test-secret
99
103
Namespace: default
100
104
Labels: <none>
@@ -105,7 +109,7 @@ username and password:
105
109
Data
106
110
====
107
111
password: 13 bytes
108
- username: 7 bytes
112
+ username: 7 bytes
109
113
```
110
114
111
115
<!--
@@ -130,6 +134,7 @@ through each step explicitly to demonstrate what is happening.
130
134
这是一种更为方便的方法。
131
135
前面展示的详细分解步骤有助于了解究竟发生了什么事情。
132
136
137
+
133
138
<!--
134
139
## Create a Pod that has access to the secret data through a Volume
135
140
@@ -145,7 +150,7 @@ Here is a configuration file you can use to create a Pod:
145
150
创建 Pod:
146
151
147
152
``` shell
148
- kubectl create -f secret-pod.yaml
153
+ kubectl apply -f https://k8s.io/examples/pods/inject/ secret-pod.yaml
149
154
```
150
155
151
156
1 . <!-- Verify that your Pod is running: -->
@@ -155,9 +160,9 @@ Here is a configuration file you can use to create a Pod:
155
160
kubectl get pod secret-test-pod
156
161
```
157
162
163
+ <!-- Output: -->
158
164
输出:
159
-
160
- ``` shell
165
+ ```
161
166
NAME READY STATUS RESTARTS AGE
162
167
secret-test-pod 1/1 Running 0 42m
163
168
```
@@ -166,7 +171,7 @@ Here is a configuration file you can use to create a Pod:
166
171
获取一个 shell 进入 Pod 中运行的容器:
167
172
168
173
``` shell
169
- kubectl exec -it secret-test-pod -- /bin/bash
174
+ kubectl exec -i -t secret-test-pod -- /bin/bash
170
175
```
171
176
172
177
1 . <!-- The secret data is exposed to the Container through a Volume mounted under
@@ -179,6 +184,7 @@ Here is a configuration file you can use to create a Pod:
179
184
在 shell 中,列举 ` /etc/secret-volume ` 目录下的文件:
180
185
181
186
``` shell
187
+ # 在容器中 Shell 运行下面命令
182
188
ls /etc/secret-volume
183
189
```
184
190
@@ -195,19 +201,18 @@ Here is a configuration file you can use to create a Pod:
195
201
In your shell, display the contents of the `username` and `password` files:
196
202
-->
197
203
在 Shell 中,显示 ` username ` 和 ` password ` 文件的内容:
198
-
199
204
``` shell
200
205
# 在容器中 Shell 运行下面命令
201
- echo " $( cat /etc/secret-volume/username) "
202
- echo " $( cat /etc/secret-volume/password) "
206
+ echo " $( cat /etc/secret-volume/username ) "
207
+ echo " $( cat /etc/secret-volume/password ) "
203
208
```
204
209
205
210
<!--
206
211
The output is your username and password:
207
212
-->
208
213
输出为用户名和密码:
209
214
210
- ``` shell
215
+ ```
211
216
my-app
212
217
39528$vdg7Jb
213
218
```
@@ -256,11 +261,14 @@ Here is a configuration file you can use to create a Pod:
256
261
kubectl exec -i -t env-single-secret -- /bin/sh -c ' echo $SECRET_USERNAME'
257
262
```
258
263
264
+ <!--
265
+ The output is
266
+ -->
259
267
输出为:
260
-
261
268
```
262
269
backend-admin
263
270
```
271
+
264
272
<!--
265
273
### Define container environment variables with data from multiple Secrets
266
274
-->
@@ -300,13 +308,16 @@ Here is a configuration file you can use to create a Pod:
300
308
``` shell
301
309
kubectl exec -i -t envvars-multiple-secrets -- /bin/sh -c ' env | grep _USERNAME'
302
310
```
303
-
311
+ <!--
312
+ The output is
313
+ -->
304
314
输出:
305
315
```
306
316
DB_USERNAME=db-admin
307
317
BACKEND_USERNAME=backend-admin
308
318
```
309
319
320
+
310
321
<!--
311
322
## Configure all key-value pairs in a Secret as container environment variables
312
323
-->
@@ -353,7 +364,10 @@ This functionality is available in Kubernetes v1.6 and later.
353
364
``` shell
354
365
kubectl exec -i -t envfrom-secret -- /bin/sh -c ' echo "username: $username\npassword: $password\n"'
355
366
```
356
-
367
+
368
+ <!--
369
+ The output is
370
+ -->
357
371
输出为:
358
372
359
373
```
@@ -364,10 +378,9 @@ This functionality is available in Kubernetes v1.6 and later.
364
378
<!-- ### References -->
365
379
### 参考
366
380
367
- * [ Secret] (/docs/api-reference/{{< param "version" >}}/#secret-v1-core)
368
- * [ Volume] (/docs/api-reference/{{< param "version" >}}/#volume-v1-core)
369
- * [ Pod] (/docs/api-reference/{{< param "version" >}}/#pod-v1-core)
370
-
381
+ * [ Secret] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
382
+ * [ Volume] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
383
+ * [ Pod] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
371
384
372
385
## {{% heading "whatsnext" %}}
373
386
0 commit comments