@@ -19,10 +19,12 @@ description: Creating Secret objects using resource configuration file.
19
19
20
20
<!-- steps -->
21
21
22
- <!-- ## Create the Config file -->
22
+ <!--
23
+ ##Create the Config file
24
+ -->
23
25
## 创建配置文件 {#create-the-config-file}
24
26
25
- <!--
27
+ <!--
26
28
You can create a Secret in a file first, in JSON or YAML format, and then
27
29
create that object. The
28
30
[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
@@ -40,7 +42,7 @@ The keys of `data` and `stringData` must consist of alphanumeric characters,
40
42
提供 ` stringData ` 字段是为了方便,它允许 Secret 使用未编码的字符串。
41
43
` data ` 和 ` stringData ` 的键必须由字母、数字、` - ` ,` _ ` 或 ` . ` 组成。
42
44
43
- <!--
45
+ <!--
44
46
For example, to store two strings in a Secret using the `data` field, convert
45
47
the strings to base64 as follows:
46
48
-->
@@ -50,7 +52,9 @@ the strings to base64 as follows:
50
52
echo -n ' admin' | base64
51
53
```
52
54
53
- <!-- The output is similar to: -->
55
+ <!--
56
+ The output is similar to:
57
+ -->
54
58
输出类似于:
55
59
56
60
```
@@ -61,14 +65,18 @@ YWRtaW4=
61
65
echo -n ' 1f2d1e2e67df' | base64
62
66
```
63
67
64
- <!-- The output is similar to: -->
68
+ <!--
69
+ The output is similar to:
70
+ -->
65
71
输出类似于:
66
72
67
73
```
68
74
MWYyZDFlMmU2N2Rm
69
75
```
70
76
71
- <!-- Write a Secret config file that looks like this: -->
77
+ <!--
78
+ Write a Secret config file that looks like this:
79
+ -->
72
80
编写一个 Secret 配置文件,如下所示:
73
81
74
82
``` yaml
86
94
Note that the name of a Secret object must be a valid
87
95
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
88
96
-->
89
- 注意,Secret 对象的名称必须是有效的 [DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
97
+ 注意,Secret 对象的名称必须是有效的 [DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。
90
98
91
99
{{< note >}}
92
100
<!--
@@ -100,7 +108,7 @@ option is not available.
100
108
Secret 数据的 JSON 和 YAML 序列化结果是以 base64 编码的。
101
109
换行符在这些字符串中无效,必须省略。
102
110
在 Darwin/macOS 上使用 `base64` 工具时,用户不应该使用 `-b` 选项分割长行。
103
- 相反地,Linux 用户 * 应该* 在 `base64` 地命令中添加 `-w 0` 选项,
111
+ 相反地,Linux 用户** 应该** 在 `base64` 地命令中添加 `-w 0` 选项,
104
112
或者在 `-w` 选项不可用的情况下,输入 `base64 | tr -d '\n'`。
105
113
{{< /note >}}
106
114
@@ -110,7 +118,7 @@ field allows you to put a non-base64 encoded string directly into the Secret,
110
118
and the string will be encoded for you when the Secret is created or updated.
111
119
-->
112
120
对于某些场景,你可能希望使用 `stringData` 字段。
113
- 这字段可以将一个非 base64 编码的字符串直接放入 Secret 中,
121
+ 这个字段可以将一个非 base64 编码的字符串直接放入 Secret 中,
114
122
当创建或更新该 Secret 时,此字段将被编码。
115
123
116
124
<!--
@@ -121,7 +129,9 @@ parts of that configuration file during your deployment process.
121
129
上述用例的实际场景可能是这样:当你部署应用时,使用 Secret 存储配置文件,
122
130
你希望在部署过程中,填入部分内容到该配置文件。
123
131
124
- <!-- For example, if your application uses the following configuration file : -->
132
+ <!--
133
+ or example, if your application uses the following configuration file :
134
+ -->
125
135
例如,如果你的应用程序使用以下配置文件 :
126
136
127
137
` ` ` yaml
@@ -130,7 +140,9 @@ username: "<user>"
130
140
password: "<password>"
131
141
` ` `
132
142
133
- <!-- You could store this in a Secret using the following definition : -->
143
+ <!--
144
+ You could store this in a Secret using the following definition :
145
+ -->
134
146
你可以使用以下定义将其存储在 Secret 中 :
135
147
136
148
` ` ` yaml
@@ -146,24 +158,32 @@ stringData:
146
158
password: <password>
147
159
` ` `
148
160
149
- <!-- # # Create the Secret object -->
161
+ <!--
162
+ # # Create the Secret object
163
+ -->
150
164
# # 创建 Secret 对象 {#create-the-secret-object}
151
165
152
- <!-- Now create the Secret using [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply): -->
166
+ <!--
167
+ Now create the Secret using [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply):
168
+ -->
153
169
现在使用 [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply) 创建 Secret:
154
170
155
171
` ` ` shell
156
172
kubectl apply -f ./secret.yaml
157
173
` ` `
158
174
159
- <!-- The output is similar to : -->
175
+ <!--
176
+ The output is similar to :
177
+ -->
160
178
输出类似于:
161
179
162
180
```
163
181
secret/mysecret created
164
182
```
165
183
166
- <!-- ## Check the Secret -->
184
+ <!--
185
+ ## Check the Secret
186
+ -->
167
187
## 检查 Secret {#check-the-secret}
168
188
169
189
<!--
@@ -178,7 +198,9 @@ retrieving Secrets. For example, if you run the following command:
178
198
kubectl get secret mysecret -o yaml
179
199
```
180
200
181
- <!-- The output is similar to: -->
201
+ <!--
202
+ The output is similar to:
203
+ -->
182
204
输出类似于:
183
205
184
206
``` yaml
@@ -204,7 +226,7 @@ To check the actual content of the encoded data, please refer to
204
226
-->
205
227
命令 `kubectl get` 和 `kubectl describe` 默认不显示 `Secret` 的内容。
206
228
这是为了防止 `Secret` 意外地暴露给旁观者或者保存在终端日志中。
207
- 检查编码数据的实际内容,请参考[解码 secret](/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret).
229
+ 检查编码数据的实际内容,请参考[解码 secret](/zh-cn/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret)。
208
230
209
231
<!--
210
232
If a field, such as `username`, is specified in both `data` and `stringData`,
@@ -225,7 +247,9 @@ stringData:
225
247
username: administrator
226
248
` ` `
227
249
228
- <!-- Results in the following Secret : -->
250
+ <!--
251
+ Results in the following Secret :
252
+ -->
229
253
结果有以下 Secret:
230
254
231
255
` ` ` yaml
@@ -242,13 +266,19 @@ metadata:
242
266
type: Opaque
243
267
` ` `
244
268
245
- <!-- Where `YWRtaW5pc3RyYXRvcg==` decodes to `administrator`. -->
269
+ <!--
270
+ Where `YWRtaW5pc3RyYXRvcg==` decodes to `administrator`.
271
+ -->
246
272
其中 `YWRtaW5pc3RyYXRvcg==` 解码成 `administrator`。
247
273
248
- <!-- # # Clean Up -->
274
+ <!--
275
+ # # Clean Up
276
+ -->
249
277
# # 清理 {#clean-up}
250
278
251
- <!-- To delete the Secret you have created : -->
279
+ <!--
280
+ To delete the Secret you have created :
281
+ -->
252
282
删除你创建的 Secret:
253
283
254
284
` ` ` shell
0 commit comments