Skip to content

Commit f7b21a5

Browse files
authored
Merge pull request #35559 from windsonsea/secconf
[zh-cn] resync /configmap-secret/managing-secret-using-config-file.md
2 parents 73818ab + ff17bdf commit f7b21a5

File tree

1 file changed

+101
-117
lines changed

1 file changed

+101
-117
lines changed

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

Lines changed: 101 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -20,97 +20,112 @@ description: Creating Secret objects using resource configuration file.
2020
<!-- steps -->
2121

2222
<!--
23-
##Create the Config file
23+
## Create the Secret {#create-the-config-file}
2424
-->
25-
## 创建配置文件 {#create-the-config-file}
25+
## 创建 Secret {#create-the-config-file}
2626

2727
<!--
28-
You can create a Secret in a file first, in JSON or YAML format, and then
29-
create that object. The
28+
You can define the `Secret` object in a manifest first, in JSON or YAML format,
29+
and then create that object. The
3030
[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
3131
resource contains two maps: `data` and `stringData`.
3232
The `data` field is used to store arbitrary data, encoded using base64. The
3333
`stringData` field is provided for convenience, and it allows you to provide
34-
Secret data as unencoded strings.
34+
the same data as unencoded strings.
3535
The keys of `data` and `stringData` must consist of alphanumeric characters,
36-
`-`, `_` or `.`.
36+
`-`, `_` or `.`.
3737
-->
38-
你可以先用 JSON 或 YAML 格式在文件中创建 Secret,然后创建该对象。
38+
你可以先用 JSON 或 YAML 格式在一个清单文件中定义 `Secret` 对象,然后创建该对象。
3939
[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
40-
资源包含2个键值对: `data``stringData`
40+
资源包含 2 个键值对:`data``stringData`
4141
`data` 字段用来存储 base64 编码的任意数据。
4242
提供 `stringData` 字段是为了方便,它允许 Secret 使用未编码的字符串。
43-
`data``stringData` 的键必须由字母、数字、`-``_``.` 组成。
43+
`data``stringData` 的键必须由字母、数字、`-``_``.` 组成。
4444

4545
<!--
46-
For example, to store two strings in a Secret using the `data` field, convert
47-
the strings to base64 as follows:
46+
The following example stores two strings in a Secret using the `data` field.
4847
-->
49-
例如,要使用 Secret 的 `data` 字段存储两个字符串,请将字符串转换为 base64 ,如下所示
48+
以下示例使用 `data` 字段在 Secret 中存储两个字符串
5049

51-
```shell
52-
echo -n 'admin' | base64
53-
```
54-
55-
<!--
56-
The output is similar to:
50+
<!--
51+
1. Convert the strings to base64:
5752
-->
58-
输出类似于:
59-
60-
```
61-
YWRtaW4=
62-
```
63-
64-
```shell
65-
echo -n '1f2d1e2e67df' | base64
66-
```
67-
68-
<!--
69-
The output is similar to:
53+
1. 将这些字符串转换为 base64:
54+
55+
```shell
56+
echo -n 'admin' | base64
57+
echo -n '1f2d1e2e67df' | base64
58+
```
59+
60+
{{< note >}}
61+
<!--
62+
The serialized JSON and YAML values of Secret data are encoded as base64 strings. Newlines are not valid within these strings and must be omitted. When using the `base64` utility on Darwin/macOS, users should avoid using the `-b` option to split long lines. Conversely, Linux users *should* add the option `-w 0` to `base64` commands or the pipeline `base64 | tr -d '\n'` if the `-w` option is not available.
63+
-->
64+
Secret 数据的 JSON 和 YAML 序列化结果是以 base64 编码的。
65+
换行符在这些字符串中无效,必须省略。
66+
在 Darwin/macOS 上使用 `base64` 工具时,用户不应该使用 `-b` 选项分割长行。
67+
相反地,Linux 用户**应该**`base64` 地命令中添加 `-w 0` 选项,
68+
或者在 `-w` 选项不可用的情况下,输入 `base64 | tr -d '\n'`
69+
{{< /note >}}
70+
71+
<!--
72+
The output is similar to:
73+
-->
74+
输出类似于:
75+
76+
```
77+
YWRtaW4=
78+
MWYyZDFlMmU2N2Rm
79+
```
80+
<!--
81+
1. Create the manifest:
7082
-->
71-
输出类似于:
72-
73-
```
74-
MWYyZDFlMmU2N2Rm
75-
```
83+
2. 创建清单:
84+
85+
```yaml
86+
apiVersion: v1
87+
kind: Secret
88+
metadata:
89+
name: mysecret
90+
type: Opaque
91+
data:
92+
username: YWRtaW4=
93+
password: MWYyZDFlMmU2N2Rm
94+
```
95+
<!--
96+
Note that the name of a Secret object must be a valid
97+
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
98+
-->
99+
注意,Secret 对象的名称必须是有效的 [DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。
76100
77-
<!--
78-
Write a Secret config file that looks like this:
101+
<!--
102+
1. Create the Secret using [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply):
79103
-->
80-
编写一个 Secret 配置文件,如下所示
104+
3. 使用 [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply) 创建 Secret
81105

82-
```yaml
83-
apiVersion: v1
84-
kind: Secret
85-
metadata:
86-
name: mysecret
87-
type: Opaque
88-
data:
89-
username: YWRtaW4=
90-
password: MWYyZDFlMmU2N2Rm
91-
```
106+
```shell
107+
kubectl apply -f ./secret.yaml
108+
```
92109

110+
<!--
111+
The output is similar to:
112+
-->
113+
输出类似于:
114+
115+
```
116+
secret/mysecret created
117+
```
93118
<!--
94-
Note that the name of a Secret object must be a valid
95-
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
119+
To verify that the Secret was created and to decode the Secret data, refer to
120+
[Managing Secrets using kubectl](/docs/tasks/configmap-secret/managing-secret-using-kubectl/#verify-the-secret).
96121
-->
97-
注意,Secret 对象的名称必须是有效的 [DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。
122+
若要验证 Secret 被创建以及想要解码 Secret 数据,
123+
请参阅[使用 kubectl 管理 Secret](/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kubectl/#verify-the-secret)
98124
99-
{{< note >}}
100-
<!--
101-
The serialized JSON and YAML values of Secret data are encoded as base64
102-
strings. Newlines are not valid within these strings and must be omitted. When
103-
using the `base64` utility on Darwin/macOS, users should avoid using the `-b`
104-
option to split long lines. Conversely, Linux users *should* add the option
105-
`-w 0` to `base64` commands or the pipeline `base64 | tr -d '\n'` if the `-w`
106-
option is not available.
125+
<!--
126+
### Specify unencoded data when creating a Secret
107127
-->
108-
Secret 数据的 JSON 和 YAML 序列化结果是以 base64 编码的。
109-
换行符在这些字符串中无效,必须省略。
110-
在 Darwin/macOS 上使用 `base64` 工具时,用户不应该使用 `-b` 选项分割长行。
111-
相反地,Linux 用户**应该**在 `base64` 地命令中添加 `-w 0` 选项,
112-
或者在 `-w` 选项不可用的情况下,输入 `base64 | tr -d '\n'`。
113-
{{< /note >}}
128+
### 创建 Secret 时提供未编码的数据 {#specify-unencoded-data-when-creating-a-secret}
114129
115130
<!--
116131
For certain scenarios, you may wish to use the `stringData` field instead. This
@@ -130,7 +145,7 @@ parts of that configuration file during your deployment process.
130145
你希望在部署过程中,填入部分内容到该配置文件。
131146
132147
<!--
133-
or example, if your application uses the following configuration file:
148+
For example, if your application uses the following configuration file:
134149
-->
135150
例如,如果你的应用程序使用以下配置文件:
136151
@@ -158,42 +173,16 @@ stringData:
158173
password: <password>
159174
```
160175
161-
<!--
162-
## Create the Secret object
163-
-->
164-
## 创建 Secret 对象 {#create-the-secret-object}
165-
166-
<!--
167-
Now create the Secret using [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply):
168-
-->
169-
现在使用 [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply) 创建 Secret:
170-
171-
```shell
172-
kubectl apply -f ./secret.yaml
173-
```
174-
175-
<!--
176-
The output is similar to:
177-
-->
178-
输出类似于:
179-
180-
```
181-
secret/mysecret created
182-
```
176+
<!--
177+
When you retrieve the Secret data, the command returns the encoded values,
178+
and not the plaintext values you provided in `stringData`.
183179

184-
<!--
185-
## Check the Secret
180+
For example, if you run the following command:
186181
-->
187-
## 检查 Secret {#check-the-secret}
182+
当你检索 Secret 数据时,此命令将返回编码的值,并不是你在 `stringData` 中提供的纯文本值。
188183

189-
<!--
190-
The `stringData` field is a write-only convenience field. It is never output when
191-
retrieving Secrets. For example, if you run the following command:
192-
-->
193-
`stringData` 字段是只写的。获取 Secret 时,此字段永远不会输出。
194184
例如,如果你运行以下命令:
195185

196-
197186
```shell
198187
kubectl get secret mysecret -o yaml
199188
```
@@ -214,26 +203,21 @@ metadata:
214203
namespace: default
215204
resourceVersion: "7225"
216205
uid: c280ad2e-e916-11e8-98f2-025000000001
217-
type: Opaque
206+
type:
218207
```
219208

220-
<!--
221-
The commands `kubectl get` and `kubectl describe` avoid showing the contents of a `Secret` by
222-
default. This is to protect the `Secret` from being exposed accidentally to an onlooker,
223-
or from being stored in a terminal log.
224-
To check the actual content of the encoded data, please refer to
225-
[decoding secret](/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret).
226-
-->
227-
命令 `kubectl get` 和 `kubectl describe` 默认不显示 `Secret` 的内容。
228-
这是为了防止 `Secret` 意外地暴露给旁观者或者保存在终端日志中。
229-
检查编码数据的实际内容,请参考[解码 secret](/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret)。
230-
231209
<!--
232-
If a field, such as `username`, is specified in both `data` and `stringData`,
233-
the value from `stringData` is used. For example, the following Secret definition:
210+
### Specifying both `data` and `stringData`
211+
212+
If you specify a field in both `data` and `stringData`, the value from `stringData` is used.
213+
214+
For example, if you define the following Secret:
234215
-->
235-
如果在 `data` 和 `stringData` 中都指定了一个字段,比如 `username`,字段值来自 `stringData`。
236-
例如,下面的 Secret 定义:
216+
### 同时指定 `data` 和 `stringData` {#specifying-both-data-and-stringdata}
217+
218+
如果你在 `data` 和 `stringData` 中设置了同一个字段,则使用来自 `stringData` 中的值。
219+
220+
例如,如果你定义以下 Secret:
237221

238222
```yaml
239223
apiVersion: v1
@@ -248,9 +232,9 @@ stringData:
248232
```
249233

250234
<!--
251-
Results in the following Secret:
235+
The `Secret` object is created as follows:
252236
-->
253-
结果有以下 Secret:
237+
所创建的 `Secret` 对象如下
254238

255239
```yaml
256240
apiVersion: v1
@@ -267,9 +251,9 @@ type: Opaque
267251
```
268252

269253
<!--
270-
Where `YWRtaW5pc3RyYXRvcg==` decodes to `administrator`.
254+
`YWRtaW5pc3RyYXRvcg==` decodes to `administrator`.
271255
-->
272-
其中 `YWRtaW5pc3RyYXRvcg==` 解码成 `administrator`。
256+
`YWRtaW5pc3RyYXRvcg==` 解码成 `administrator`。
273257

274258
<!--
275259
## Clean Up

0 commit comments

Comments
 (0)