@@ -58,7 +58,7 @@ Run the following command:
58
58
59
59
``` shell
60
60
kubectl create secret generic db-user-pass \
61
- --from-literal=username=devuser \
61
+ --from-literal=username=admin \
62
62
--from-literal=password=' S!B\*d$zDsb='
63
63
```
64
64
@@ -67,7 +67,7 @@ You must use single quotes `''` to escape special characters such as `$`, `\`,
67
67
`*`, `=`, and `!` in your strings. If you don't, your shell will interpret these
68
68
characters.
69
69
-->
70
- 你必须使用单引号 ` '' ` 转义字符串中的特殊字符,如 ` $ ` 、` \ ` 、` * ` 、` = ` 和` ! ` 。否则,你的 shell
70
+ 你必须使用单引号 ` '' ` 转义字符串中的特殊字符,如 ` $ ` 、` \ ` 、` * ` 、` = ` 和` ! ` 。否则,你的 shell
71
71
将会解析这些字符。
72
72
73
73
<!--
@@ -78,44 +78,46 @@ characters.
78
78
<!--
79
79
1. Store the credentials in files with the values encoded in base64:
80
80
-->
81
- 1 . 对凭证的取值作 base64 编码后保存到文件中:
82
-
83
- ``` shell
84
- echo -n ' admin' | base64 > ./username.txt
85
- echo -n ' S!B\*d$zDsb=' | base64 > ./password.txt
86
- ```
87
- < ! --
88
- The ` -n` flag ensures that the generated files do not have an extra newline
89
- character at the end of the text. This is important because when ` kubectl`
90
- reads a file and encodes the content into a base64 string, the extra
91
- newline character gets encoded too. You do not need to escape special
92
- characters in strings that you include in a file.
93
- -->
94
- ` -n` 标志用来确保生成文件的文末没有多余的换行符。这很重要,因为当 ` kubectl`
95
- 读取文件并将内容编码为 base64 字符串时,额外的换行符也会被编码。
96
- 你不需要对文件中包含的字符串中的特殊字符进行转义。
81
+ 1 . 对凭证的取值作 base64 编码后保存到文件中:
82
+
83
+ ``` shell
84
+ echo -n ' admin' | base64 > ./username.txt
85
+ echo -n ' S!B\*d$zDsb=' | base64 > ./password.txt
86
+ ```
87
+
88
+ <!--
89
+ The `-n` flag ensures that the generated files do not have an extra newline
90
+ character at the end of the text. This is important because when `kubectl`
91
+ reads a file and encodes the content into a base64 string, the extra
92
+ newline character gets encoded too. You do not need to escape special
93
+ characters in strings that you include in a file.
94
+ -->
95
+ `-n` 标志用来确保生成文件的文末没有多余的换行符。这很重要,因为当 `kubectl`
96
+ 读取文件并将内容编码为 base64 字符串时,额外的换行符也会被编码。
97
+ 你不需要对文件中包含的字符串中的特殊字符进行转义。
97
98
98
99
<!--
99
100
2. Pass the file paths in the `kubectl` command:
100
101
-->
101
- 2. 在 ` kubectl` 命令中传递文件路径:
102
-
103
- ` ` ` shell
104
- kubectl create secret generic db-user-pass \
105
- --from-file=./username.txt \
106
- --from-file=./password.txt
107
- ` ` `
108
- < ! --
109
- The default key name is the file name. You can optionally set the key name
110
- using ` --from-file=[key= ]source` . For example:
111
- -->
112
- 默认键名为文件名。你也可以通过 ` --from-file=[key= ]source` 设置键名,例如:
113
-
114
- ` ` ` shell
115
- kubectl create secret generic db-user-pass \
116
- --from-file=username=./username.txt \
117
- --from-file=password=./password.txt
118
- ` ` `
102
+ 2 . 在 ` kubectl ` 命令中传递文件路径:
103
+
104
+ ``` shell
105
+ kubectl create secret generic db-user-pass \
106
+ --from-file=./username.txt \
107
+ --from-file=./password.txt
108
+ ```
109
+
110
+ <!--
111
+ The default key name is the file name. You can optionally set the key name
112
+ using `--from-file=[key=]source`. For example:
113
+ -->
114
+ 默认键名为文件名。你也可以通过 `--from-file=[key=]source` 设置键名,例如:
115
+
116
+ ``` shell
117
+ kubectl create secret generic db-user-pass \
118
+ --from-file=username=./username.txt \
119
+ --from-file=password=./password.txt
120
+ ```
119
121
120
122
<!--
121
123
With either method, the output is similar to:
@@ -140,11 +142,14 @@ Check that the Secret was created:
140
142
kubectl get secrets
141
143
```
142
144
145
+ <!--
146
+ The output is similar to:
147
+ -->
143
148
输出类似于:
144
149
145
150
```
146
- NAME TYPE DATA AGE
147
- db-user-pass Opaque 2 51s
151
+ NAME TYPE DATA AGE
152
+ db-user-pass Opaque 2 51s
148
153
```
149
154
150
155
<!--
@@ -191,48 +196,55 @@ accidentally, or from being stored in a terminal log.
191
196
<!--
192
197
1. View the contents of the Secret you created:
193
198
-->
194
- 1 . 查看你所创建的 Secret 内容
195
-
196
- ``` shell
197
- kubectl get secret db-user-pass -o jsonpath=' {.data}'
198
- ```
199
-
200
- < ! -- The output is similar to: -->
201
- 输出类似于:
199
+ 1 . 查看你所创建的 Secret 内容
202
200
203
- ` ` ` json
204
- { " password " : " UyFCXCpkJHpEc2I9 " , " username " : " YWRtaW4= " }
205
- ` ` `
201
+ ``` shell
202
+ kubectl get secret db-user-pass -o jsonpath= ' {.data} '
203
+ ```
206
204
207
- < ! -- 2. Decode the ` password` data: -->
208
- 2. 解码 ` password` 数据:
205
+ <!--
206
+ The output is similar to:
207
+ -->
208
+ 输出类似于:
209
209
210
- ` ` ` shell
211
- echo ' UyFCXCpkJHpEc2I9' | base64 --decode
212
- ` ` `
210
+ ``` json
211
+ { "password" : " UyFCXCpkJHpEc2I9" , "username" : " YWRtaW4= " }
212
+ ```
213
213
214
- < ! -- The output is similar to: -->
215
- 输出类似于:
216
-
217
- ```
218
- S! B\* d$zDsb =
219
- ```
220
-
221
- < ! --
222
- {{< caution> }}This is an example for documentation purposes. In practice,
223
- this method could cause the command with the encoded data to be stored in
224
- your shell history. Anyone with access to your computer could find the
225
- command and decode the secret. A better approach is to combine the view and
226
- decode commands.{{< /caution> }}
227
- -->
228
- {{< caution> }}
229
- 这是一个出于文档编制目的的示例。实际上,该方法可能会导致包含编码数据的命令存储在
230
- Shell 的历史记录中。任何可以访问你的计算机的人都可以找到该命令并对 Secret 进行解码。
231
- 更好的办法是将查看和解码命令一同使用。{{< /caution> }}
232
-
233
- ` ` ` shell
234
- kubectl get secret db-user-pass -o jsonpath=' {.data.password}' | base64 --decode
235
- ` ` `
214
+ <!--
215
+ 2. Decode the `password` data:
216
+ -->
217
+ 2 . 解码 ` password ` 数据:
218
+
219
+ ``` shell
220
+ echo ' UyFCXCpkJHpEc2I9' | base64 --decode
221
+ ```
222
+
223
+ <!--
224
+ The output is similar to:
225
+ -->
226
+ 输出类似于:
227
+
228
+ ```
229
+ S!B\*d$zDsb=
230
+ ```
231
+
232
+ {{< caution >}}
233
+ <!--
234
+ This is an example for documentation purposes. In practice,
235
+ this method could cause the command with the encoded data to be stored in
236
+ your shell history. Anyone with access to your computer could find the
237
+ command and decode the secret. A better approach is to combine the view and
238
+ decode commands.
239
+ -->
240
+ 这是一个出于文档编制目的的示例。实际上,该方法可能会导致包含编码数据的命令存储在
241
+ Shell 的历史记录中。任何可以访问你的计算机的人都可以找到该命令并对 Secret 进行解码。
242
+ 更好的办法是将查看和解码命令一同使用。
243
+ {{< /caution >}}
244
+
245
+ ``` shell
246
+ kubectl get secret db-user-pass -o jsonpath=' {.data.password}' | base64 --decode
247
+ ```
236
248
237
249
<!--
238
250
## Edit a Secret {#edit-secret}
@@ -256,6 +268,7 @@ This opens your default editor and allows you to update the base64 encoded
256
268
Secret values in the `data` field, such as in the following example:
257
269
-->
258
270
这将打开默认编辑器,并允许你更新 ` data ` 字段中的 base64 编码的 Secret 值,示例如下:
271
+
259
272
<!--
260
273
# Please edit the object below. Lines beginning with a '#' will be ignored,
261
274
# and an empty file will abort the edit. If an error occurs while saving this file, it will be
@@ -264,11 +277,9 @@ Secret values in the `data` field, such as in the following example:
264
277
-->
265
278
266
279
``` yaml
267
-
268
280
# 请编辑下面的对象。以“#”开头的行将被忽略,
269
281
# 空文件将中止编辑。如果在保存此文件时发生错误,
270
282
# 则将重新打开该文件并显示相关的失败。
271
- #
272
283
apiVersion : v1
273
284
data :
274
285
password : UyFCXCpkJHpEc2I9
@@ -297,17 +308,13 @@ To delete a Secret, run the following command:
297
308
kubectl delete secret db-user-pass
298
309
```
299
310
300
- < ! --
301
- discussion
302
- -->
303
-
304
311
## {{% heading "whatsnext" %}}
305
312
306
313
<!--
307
314
- Read more about the [Secret concept](/docs/concepts/configuration/secret/)
308
- - Learn how to [manage Secrets using config files ](/docs/tasks/configmap-secret/managing-secret-using-config-file/)
315
+ - Learn how to [manage Secrets using config file ](/docs/tasks/configmap-secret/managing-secret-using-config-file/)
309
316
- Learn how to [manage Secrets using kustomize](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
310
317
-->
311
318
- 进一步阅读 [ Secret 概念] ( /zh-cn/docs/concepts/configuration/secret/ )
312
319
- 了解如何[ 使用配置文件管理 Secret] ( /zh-cn/docs/tasks/configmap-secret/managing-secret-using-config-file/ )
313
- - 了解如何[使用 kustomize 管理 Secret](/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
320
+ - 了解如何[ 使用 Kustomize 管理 Secret] ( /zh-cn/docs/tasks/configmap-secret/managing-secret-using-kustomize/ )
0 commit comments