Skip to content

Commit 7e1192f

Browse files
committed
[zh] sync managing-secret-using-kubectl.md
1 parent 3d813eb commit 7e1192f

File tree

1 file changed

+91
-84
lines changed

1 file changed

+91
-84
lines changed

content/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kubectl.md

Lines changed: 91 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Run the following command:
5858

5959
```shell
6060
kubectl create secret generic db-user-pass \
61-
--from-literal=username=devuser \
61+
--from-literal=username=admin \
6262
--from-literal=password='S!B\*d$zDsb='
6363
```
6464

@@ -67,7 +67,7 @@ You must use single quotes `''` to escape special characters such as `$`, `\`,
6767
`*`, `=`, and `!` in your strings. If you don't, your shell will interpret these
6868
characters.
6969
-->
70-
你必须使用单引号 `''` 转义字符串中的特殊字符,如 `$``\``*``=``!` 。否则,你的 shell
70+
你必须使用单引号 `''` 转义字符串中的特殊字符,如 `$``\``*``=``!` 。否则,你的 shell
7171
将会解析这些字符。
7272

7373
<!--
@@ -78,44 +78,46 @@ characters.
7878
<!--
7979
1. Store the credentials in files with the values encoded in base64:
8080
-->
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+
你不需要对文件中包含的字符串中的特殊字符进行转义。
9798

9899
<!--
99100
2. Pass the file paths in the `kubectl` command:
100101
-->
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+
```
119121

120122
<!--
121123
With either method, the output is similar to:
@@ -140,11 +142,14 @@ Check that the Secret was created:
140142
kubectl get secrets
141143
```
142144

145+
<!--
146+
The output is similar to:
147+
-->
143148
输出类似于:
144149

145150
```
146-
NAME TYPE DATA AGE
147-
db-user-pass Opaque 2 51s
151+
NAME TYPE DATA AGE
152+
db-user-pass Opaque 2 51s
148153
```
149154

150155
<!--
@@ -191,48 +196,55 @@ accidentally, or from being stored in a terminal log.
191196
<!--
192197
1. View the contents of the Secret you created:
193198
-->
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 内容
202200

203-
```json
204-
{"password":"UyFCXCpkJHpEc2I9","username":"YWRtaW4="}
205-
```
201+
```shell
202+
kubectl get secret db-user-pass -o jsonpath='{.data}'
203+
```
206204

207-
<!-- 2. Decode the `password` data: -->
208-
2. 解码 `password` 数据:
205+
<!--
206+
The output is similar to:
207+
-->
208+
输出类似于:
209209

210-
```shell
211-
echo 'UyFCXCpkJHpEc2I9' | base64 --decode
212-
```
210+
```json
211+
{"password":"UyFCXCpkJHpEc2I9","username":"YWRtaW4="}
212+
```
213213

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+
```
236248

237249
<!--
238250
## Edit a Secret {#edit-secret}
@@ -256,6 +268,7 @@ This opens your default editor and allows you to update the base64 encoded
256268
Secret values in the `data` field, such as in the following example:
257269
-->
258270
这将打开默认编辑器,并允许你更新 `data` 字段中的 base64 编码的 Secret 值,示例如下:
271+
259272
<!--
260273
# Please edit the object below. Lines beginning with a '#' will be ignored,
261274
# 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:
264277
-->
265278

266279
```yaml
267-
268280
#请编辑下面的对象。以“#”开头的行将被忽略,
269281
#空文件将中止编辑。如果在保存此文件时发生错误,
270282
#则将重新打开该文件并显示相关的失败。
271-
#
272283
apiVersion: v1
273284
data:
274285
password: UyFCXCpkJHpEc2I9
@@ -297,17 +308,13 @@ To delete a Secret, run the following command:
297308
kubectl delete secret db-user-pass
298309
```
299310

300-
<!--
301-
discussion
302-
-->
303-
304311
## {{% heading "whatsnext" %}}
305312

306313
<!--
307314
- 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/)
309316
- Learn how to [manage Secrets using kustomize](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
310317
-->
311318
- 进一步阅读 [Secret 概念](/zh-cn/docs/concepts/configuration/secret/)
312319
- 了解如何[使用配置文件管理 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

Comments
 (0)