Switch language name 'zh' to 'zh-cn'
This is the first step to rename 'zh' to 'zh-cn'. There are several reasons why we rename the language name.
- The upstream docsy theme changed the language name, leading to many warnings during site build;
The side-effect is that the i18n strings are no longer working.
- We believe renaming the language is the right thing to do, because this move can make room for other variants of Chinese language, such as 'zh-tw', 'zh-sg' etc.
There would be several follow-ups to this PR, such as fixing the intra-site links, adding redirects etc.
We will lock up changes to zh/zh-cn pages for the moment, until this one gets in.
This PR is based on commit cdad0a7342.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
title: "管理 Secrets"
|
||||
weight: 28
|
||||
description: 使用 Secrets 管理机密配置数据。
|
||||
---
|
||||
@@ -0,0 +1,268 @@
|
||||
---
|
||||
title: 使用配置文件管理 Secret
|
||||
content_type: task
|
||||
weight: 20
|
||||
description: 使用资源配置文件创建 Secret 对象。
|
||||
---
|
||||
<!--
|
||||
title: Managing Secrets using Configuration File
|
||||
content_type: task
|
||||
weight: 20
|
||||
description: Creating Secret objects using resource configuration file.
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
<!-- ## Create the Config file -->
|
||||
## 创建配置文件 {#create-the-config-file}
|
||||
|
||||
<!--
|
||||
You can create a Secret in a file first, in JSON or YAML format, and then
|
||||
create that object. The
|
||||
[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
|
||||
resource contains two maps: `data` and `stringData`.
|
||||
The `data` field is used to store arbitrary data, encoded using base64. The
|
||||
`stringData` field is provided for convenience, and it allows you to provide
|
||||
Secret data as unencoded strings.
|
||||
The keys of `data` and `stringData` must consist of alphanumeric characters,
|
||||
`-`, `_` or `.`.
|
||||
-->
|
||||
你可以先用 JSON 或 YAML 格式在文件中创建 Secret,然后创建该对象。
|
||||
[Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
|
||||
资源包含2个键值对: `data` 和 `stringData`。
|
||||
`data` 字段用来存储 base64 编码的任意数据。
|
||||
提供 `stringData` 字段是为了方便,它允许 Secret 使用未编码的字符串。
|
||||
`data` 和 `stringData` 的键必须由字母、数字、`-`,`_` 或 `.` 组成。
|
||||
|
||||
<!--
|
||||
For example, to store two strings in a Secret using the `data` field, convert
|
||||
the strings to base64 as follows:
|
||||
-->
|
||||
例如,要使用 Secret 的 `data` 字段存储两个字符串,请将字符串转换为 base64 ,如下所示:
|
||||
|
||||
```shell
|
||||
echo -n 'admin' | base64
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
YWRtaW4=
|
||||
```
|
||||
|
||||
```shell
|
||||
echo -n '1f2d1e2e67df' | base64
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
MWYyZDFlMmU2N2Rm
|
||||
```
|
||||
|
||||
<!-- Write a Secret config file that looks like this: -->
|
||||
编写一个 Secret 配置文件,如下所示:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mysecret
|
||||
type: Opaque
|
||||
data:
|
||||
username: YWRtaW4=
|
||||
password: MWYyZDFlMmU2N2Rm
|
||||
```
|
||||
|
||||
<!--
|
||||
Note that the name of a Secret object must be a valid
|
||||
[DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
|
||||
-->
|
||||
注意,Secret 对象的名称必须是有效的 [DNS 子域名](/zh/docs/concepts/overview/working-with-objects/names#dns-subdomain-names).
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
Secret 数据的 JSON 和 YAML 序列化结果是以 base64 编码的。
|
||||
换行符在这些字符串中无效,必须省略。
|
||||
在 Darwin/macOS 上使用 `base64` 工具时,用户不应该使用 `-b` 选项分割长行。
|
||||
相反地,Linux 用户 *应该* 在 `base64` 地命令中添加 `-w 0` 选项,
|
||||
或者在 `-w` 选项不可用的情况下,输入 `base64 | tr -d '\n'`。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
For certain scenarios, you may wish to use the `stringData` field instead. This
|
||||
field allows you to put a non-base64 encoded string directly into the Secret,
|
||||
and the string will be encoded for you when the Secret is created or updated.
|
||||
-->
|
||||
对于某些场景,你可能希望使用 `stringData` 字段。
|
||||
这字段可以将一个非 base64 编码的字符串直接放入 Secret 中,
|
||||
当创建或更新该 Secret 时,此字段将被编码。
|
||||
|
||||
<!--
|
||||
A practical example of this might be where you are deploying an application
|
||||
that uses a Secret to store a configuration file, and you want to populate
|
||||
parts of that configuration file during your deployment process.
|
||||
-->
|
||||
上述用例的实际场景可能是这样:当你部署应用时,使用 Secret 存储配置文件,
|
||||
你希望在部署过程中,填入部分内容到该配置文件。
|
||||
|
||||
<!-- For example, if your application uses the following configuration file: -->
|
||||
例如,如果你的应用程序使用以下配置文件:
|
||||
|
||||
```yaml
|
||||
apiUrl: "https://my.api.com/api/v1"
|
||||
username: "<user>"
|
||||
password: "<password>"
|
||||
```
|
||||
|
||||
<!-- You could store this in a Secret using the following definition: -->
|
||||
你可以使用以下定义将其存储在 Secret 中:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mysecret
|
||||
type: Opaque
|
||||
stringData:
|
||||
config.yaml: |
|
||||
apiUrl: "https://my.api.com/api/v1"
|
||||
username: <user>
|
||||
password: <password>
|
||||
```
|
||||
|
||||
<!-- ## Create the Secret object -->
|
||||
## 创建 Secret 对象 {#create-the-secret-object}
|
||||
|
||||
<!-- Now create the Secret using [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply): -->
|
||||
现在使用 [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands#apply) 创建 Secret:
|
||||
|
||||
```shell
|
||||
kubectl apply -f ./secret.yaml
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
secret/mysecret created
|
||||
```
|
||||
|
||||
<!-- ## Check the Secret -->
|
||||
## 检查 Secret {#check-the-secret}
|
||||
|
||||
<!--
|
||||
The `stringData` field is a write-only convenience field. It is never output when
|
||||
retrieving Secrets. For example, if you run the following command:
|
||||
-->
|
||||
`stringData` 字段是只写的。获取 Secret 时,此字段永远不会输出。
|
||||
例如,如果你运行以下命令:
|
||||
|
||||
|
||||
```shell
|
||||
kubectl get secret mysecret -o yaml
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
data:
|
||||
config.yaml: YXBpVXJsOiAiaHR0cHM6Ly9teS5hcGkuY29tL2FwaS92MSIKdXNlcm5hbWU6IHt7dXNlcm5hbWV9fQpwYXNzd29yZDoge3twYXNzd29yZH19
|
||||
kind: Secret
|
||||
metadata:
|
||||
creationTimestamp: 2018-11-15T20:40:59Z
|
||||
name: mysecret
|
||||
namespace: default
|
||||
resourceVersion: "7225"
|
||||
uid: c280ad2e-e916-11e8-98f2-025000000001
|
||||
type: Opaque
|
||||
```
|
||||
|
||||
<!--
|
||||
The commands `kubectl get` and `kubectl describe` avoid showing the contents of a `Secret` by
|
||||
default. This is to protect the `Secret` from being exposed accidentally to an onlooker,
|
||||
or from being stored in a terminal log.
|
||||
To check the actual content of the encoded data, please refer to
|
||||
[decoding secret](/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret).
|
||||
-->
|
||||
命令 `kubectl get` 和 `kubectl describe` 默认不显示 `Secret` 的内容。
|
||||
这是为了防止 `Secret` 意外地暴露给旁观者或者保存在终端日志中。
|
||||
检查编码数据的实际内容,请参考[解码 secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret).
|
||||
|
||||
<!--
|
||||
If a field, such as `username`, is specified in both `data` and `stringData`,
|
||||
the value from `stringData` is used. For example, the following Secret definition:
|
||||
-->
|
||||
如果在 `data` 和 `stringData` 中都指定了一个字段,比如 `username`,字段值来自 `stringData`。
|
||||
例如,下面的 Secret 定义:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: mysecret
|
||||
type: Opaque
|
||||
data:
|
||||
username: YWRtaW4=
|
||||
stringData:
|
||||
username: administrator
|
||||
```
|
||||
|
||||
<!-- Results in the following Secret: -->
|
||||
结果有以下 Secret:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
data:
|
||||
username: YWRtaW5pc3RyYXRvcg==
|
||||
kind: Secret
|
||||
metadata:
|
||||
creationTimestamp: 2018-11-15T20:46:46Z
|
||||
name: mysecret
|
||||
namespace: default
|
||||
resourceVersion: "7579"
|
||||
uid: 91460ecb-e917-11e8-98f2-025000000001
|
||||
type: Opaque
|
||||
```
|
||||
|
||||
<!-- Where `YWRtaW5pc3RyYXRvcg==` decodes to `administrator`. -->
|
||||
其中 `YWRtaW5pc3RyYXRvcg==` 解码成 `administrator`。
|
||||
|
||||
<!-- ## Clean Up -->
|
||||
## 清理 {#clean-up}
|
||||
|
||||
<!-- To delete the Secret you have created: -->
|
||||
删除你创建的 Secret:
|
||||
|
||||
```shell
|
||||
kubectl delete secret mysecret
|
||||
```
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
<!--
|
||||
- Read more about the [Secret concept](/docs/concepts/configuration/secret/)
|
||||
- Learn how to [manage Secrets with the `kubectl` command](/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
|
||||
- Learn how to [manage Secrets using kustomize](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
|
||||
-->
|
||||
- 进一步阅读 [Secret 概念](/zh/docs/concepts/configuration/secret/)
|
||||
- 了解如何[使用 `kubectl` 命令管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
|
||||
- 了解如何[使用 kustomize 管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
|
||||
|
||||
@@ -0,0 +1,237 @@
|
||||
---
|
||||
title: 使用 kubectl 管理 Secret
|
||||
content_type: task
|
||||
weight: 10
|
||||
description: 使用 kubectl 命令行创建 Secret 对象。
|
||||
---
|
||||
<!--
|
||||
title: Managing Secrets using kubectl
|
||||
content_type: task
|
||||
weight: 10
|
||||
description: Creating Secret objects using kubectl command line.
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
<!-- ## Create a Secret -->
|
||||
## 创建 Secret {#create-a-secret}
|
||||
|
||||
<!--
|
||||
A `Secret` can contain user credentials required by pods to access a database.
|
||||
For example, a database connection string consists of a username and password.
|
||||
You can store the username in a file `./username.txt` and the password in a
|
||||
file `./password.txt` on your local machine.
|
||||
-->
|
||||
一个 `Secret` 可以包含 Pod 访问数据库所需的用户凭证。
|
||||
例如,由用户名和密码组成的数据库连接字符串。
|
||||
你可以在本地计算机上,将用户名存储在文件 `./username.txt` 中,将密码存储在文件 `./password.txt` 中。
|
||||
|
||||
```shell
|
||||
echo -n 'admin' > ./username.txt
|
||||
echo -n '1f2d1e2e67df' > ./password.txt
|
||||
```
|
||||
|
||||
<!--
|
||||
In these commands, the `-n` flag ensures that the generated files do not have
|
||||
an extra newline character at the end of the text. This is important because
|
||||
when `kubectl` reads a file and encodes the content into a base64 string, the
|
||||
extra newline character gets encoded too.
|
||||
-->
|
||||
在这些命令中,`-n` 标志确保生成的文件在文本末尾不包含额外的换行符。
|
||||
这一点很重要,因为当 `kubectl` 读取文件并将内容编码为 base64 字符串时,多余的换行符也会被编码。
|
||||
|
||||
<!--
|
||||
The `kubectl create secret` command packages these files into a Secret and creates
|
||||
the object on the API server.
|
||||
-->
|
||||
`kubectl create secret` 命令将这些文件打包成一个 Secret 并在 API 服务器上创建对象。
|
||||
|
||||
```shell
|
||||
kubectl create secret generic db-user-pass \
|
||||
--from-file=./username.txt \
|
||||
--from-file=./password.txt
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
secret/db-user-pass created
|
||||
```
|
||||
|
||||
<!--
|
||||
The default key name is the filename. You can optionally set the key name using
|
||||
`--from-file=[key=]source`. For example:
|
||||
-->
|
||||
默认密钥名称是文件名。 你可以选择使用 `--from-file=[key=]source` 来设置密钥名称。例如:
|
||||
|
||||
```shell
|
||||
kubectl create secret generic db-user-pass \
|
||||
--from-file=username=./username.txt \
|
||||
--from-file=password=./password.txt
|
||||
```
|
||||
|
||||
<!--
|
||||
You do not need to escape special characters in password strings that you
|
||||
include in a file.
|
||||
-->
|
||||
你不需要对文件中包含的密码字符串中的特殊字符进行转义。
|
||||
|
||||
<!--
|
||||
You can also provide Secret data using the `--from-literal=<key>=<value>` tag.
|
||||
This tag can be specified more than once to provide multiple key-value pairs.
|
||||
Note that special characters such as `$`, `\`, `*`, `=`, and `!` will be
|
||||
interpreted by your [shell](https://en.wikipedia.org/wiki/Shell_(computing))
|
||||
and require escaping.
|
||||
|
||||
In most shells, the easiest way to escape the password is to surround it with
|
||||
single quotes (`'`). For example, if your password is `S!B\*d$zDsb=`,
|
||||
run the following command:
|
||||
-->
|
||||
你还可以使用 `--from-literal=<key>=<value>` 标签提供 Secret 数据。
|
||||
可以多次使用此标签,提供多个键值对。
|
||||
请注意,特殊字符(例如:`$`,`\`,`*`,`=` 和 `!`)由你的 [shell](https://en.wikipedia.org/wiki/Shell_(computing))
|
||||
解释执行,而且需要转义。
|
||||
|
||||
在大多数 shell 中,转义密码最简便的方法是用单引号括起来。
|
||||
比如,如果你的密码是 `S!B\*d$zDsb=`,
|
||||
可以像下面一样执行命令:
|
||||
|
||||
```shell
|
||||
kubectl create secret generic db-user-pass \
|
||||
--from-literal=username=devuser \
|
||||
--from-literal=password='S!B\*d$zDsb='
|
||||
```
|
||||
|
||||
<!-- ## Verify the Secret -->
|
||||
## 验证 Secret {#verify-the-secret}
|
||||
|
||||
<!-- Check that the Secret was created: -->
|
||||
检查 secret 是否已创建:
|
||||
|
||||
```shell
|
||||
kubectl get secrets
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
NAME TYPE DATA AGE
|
||||
db-user-pass Opaque 2 51s
|
||||
```
|
||||
|
||||
<!-- You can view a description of the `Secret`: -->
|
||||
你可以查看 `Secret` 的描述:
|
||||
|
||||
```shell
|
||||
kubectl describe secrets/db-user-pass
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
Name: db-user-pass
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Type: Opaque
|
||||
|
||||
Data
|
||||
====
|
||||
password: 12 bytes
|
||||
username: 5 bytes
|
||||
```
|
||||
|
||||
<!--
|
||||
The commands `kubectl get` and `kubectl describe` avoid showing the contents
|
||||
of a `Secret` by default. This is to protect the `Secret` from being exposed
|
||||
accidentally, or from being stored in a terminal log.
|
||||
-->
|
||||
`kubectl get` 和 `kubectl describe` 命令默认不显示 `Secret` 的内容。
|
||||
这是为了防止 `Secret` 被意外暴露或存储在终端日志中。
|
||||
|
||||
<!-- ## Decoding the Secret {#decoding-secret} -->
|
||||
## 解码 Secret {#decoding-secret}
|
||||
|
||||
<!--
|
||||
To view the contents of the Secret you created, run the following command:
|
||||
-->
|
||||
要查看创建的 Secret 的内容,运行以下命令:
|
||||
|
||||
```shell
|
||||
kubectl get secret db-user-pass -o jsonpath='{.data}'
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```json
|
||||
{"password":"MWYyZDFlMmU2N2Rm","username":"YWRtaW4="}
|
||||
```
|
||||
|
||||
<!--
|
||||
Now you can decode the `password` data:
|
||||
-->
|
||||
现在你可以解码 `password` 的数据:
|
||||
|
||||
```shell
|
||||
# 这是一个用于文档说明的示例。
|
||||
# 如果你这样做,数据 'MWYyZDFlMmU2N2Rm' 可以存储在你的 shell 历史中。
|
||||
# 可以进入你电脑的人可以找到那个记住的命令并可以在你不知情的情况下 base-64 解码这个 Secret。
|
||||
# 通常最好将这些步骤结合起来,如页面后面所示。
|
||||
echo 'MWYyZDFlMmU2N2Rm' | base64 --decode
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
1f2d1e2e67df
|
||||
```
|
||||
|
||||
<!--
|
||||
In order to avoid storing a secret encoded value in your shell history, you can
|
||||
run the following command:
|
||||
-->
|
||||
为了避免在 shell 历史记录中存储 Secret 的编码值,可以执行如下命令:
|
||||
|
||||
```shell
|
||||
kubectl get secret db-user-pass -o jsonpath='{.data.password}' | base64 --decode
|
||||
```
|
||||
|
||||
<!--
|
||||
The output shall be similar as above.
|
||||
-->
|
||||
输出应与上述类似。
|
||||
|
||||
<!-- ## Clean Up -->
|
||||
## 清理 {#clean-up}
|
||||
|
||||
<!-- Delete the Secret you created: -->
|
||||
删除创建的 Secret:
|
||||
|
||||
```shell
|
||||
kubectl delete secret db-user-pass
|
||||
```
|
||||
|
||||
<!-- discussion -->
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
<!--
|
||||
- Read more about the [Secret concept](/docs/concepts/configuration/secret/)
|
||||
- Learn how to [manage Secrets using config files](/docs/tasks/configmap-secret/managing-secret-using-config-file/)
|
||||
- Learn how to [manage Secrets using kustomize](/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
|
||||
-->
|
||||
- 进一步阅读 [Secret 概念](/zh/docs/concepts/configuration/secret/)
|
||||
- 了解如何[使用配置文件管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-config-file/)
|
||||
- 了解如何[使用 kustomize 管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kustomize/)
|
||||
@@ -0,0 +1,192 @@
|
||||
---
|
||||
title: 使用 Kustomize 管理 Secret
|
||||
content_type: task
|
||||
weight: 30
|
||||
description: 使用 kustomization.yaml 文件创建 Secret 对象。
|
||||
---
|
||||
<!--
|
||||
title: Managing Secrets using Kustomize
|
||||
content_type: task
|
||||
weight: 30
|
||||
description: Creating Secret objects using kustomization.yaml file.
|
||||
-->
|
||||
|
||||
<!-- overview -->
|
||||
|
||||
<!--
|
||||
Since Kubernetes v1.14, `kubectl` supports
|
||||
[managing objects using Kustomize](/docs/tasks/manage-kubernetes-objects/kustomization/).
|
||||
Kustomize provides resource Generators to create Secrets and ConfigMaps. The
|
||||
Kustomize generators should be specified in a `kustomization.yaml` file inside
|
||||
a directory. After generating the Secret, you can create the Secret on the API
|
||||
server with `kubectl apply`.
|
||||
-->
|
||||
从 kubernetes v1.14 开始,`kubectl` 支持[使用 Kustomize 管理对象](/zh/docs/tasks/manage-kubernetes-objects/kustomization/)。
|
||||
Kustomize 提供了资源生成器(Generators)来创建 Secret 和 ConfigMap。
|
||||
Kustomize 生成器应该在某个目录的 `kustomization.yaml` 文件中指定。
|
||||
生成 Secret 后,你可以使用 `kubectl apply` 在 API 服务器上创建该 Secret。
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
{{< include "task-tutorial-prereqs.md" >}}
|
||||
|
||||
<!-- steps -->
|
||||
|
||||
<!-- ## Create the Kustomization file -->
|
||||
## 创建 Kustomization 文件 {#create-the-kustomization-file}
|
||||
|
||||
<!--
|
||||
You can generate a Secret by defining a `secretGenerator` in a
|
||||
`kustomization.yaml` file that references other existing files.
|
||||
For example, the following kustomization file references the
|
||||
`./username.txt` and the `./password.txt` files:
|
||||
-->
|
||||
你可以在 `kustomization.yaml` 中定义 `secreteGenerator`,并在定义中引用其他现成的文件,生成 Secret。
|
||||
例如:下面的 kustomization 文件 引用了 `./username.txt` 和 `./password.txt` 文件:
|
||||
|
||||
```yaml
|
||||
secretGenerator:
|
||||
- name: db-user-pass
|
||||
files:
|
||||
- username.txt
|
||||
- password.txt
|
||||
```
|
||||
|
||||
<!--
|
||||
You can also define the `secretGenerator` in the `kustomization.yaml`
|
||||
file by providing some literals.
|
||||
For example, the following `kustomization.yaml` file contains two literals
|
||||
for `username` and `password` respectively:
|
||||
-->
|
||||
你也可以在 `kustomization.yaml` 文件中指定一些字面量定义 `secretGenerator`。
|
||||
例如:下面的 `kustomization.yaml` 文件中包含了 `username` 和 `password` 两个字面量:
|
||||
|
||||
```yaml
|
||||
secretGenerator:
|
||||
- name: db-user-pass
|
||||
literals:
|
||||
- username=admin
|
||||
- password=1f2d1e2e67df
|
||||
```
|
||||
|
||||
<!--
|
||||
You can also define the `secretGenerator` in the `kustomization.yaml`
|
||||
file by providing `.env` files.
|
||||
For example, the following `kustomization.yaml` file pulls in data from
|
||||
`.env.secret` file:
|
||||
-->
|
||||
你也可以使用 `.env` 文件在 `kustomization.yaml` 中定义 `secretGenerator`。
|
||||
例如:下面的 `kustomization.yaml` 文件从 `.env.secret` 文件获取数据。
|
||||
|
||||
```yaml
|
||||
secretGenerator:
|
||||
- name: db-user-pass
|
||||
envs:
|
||||
- .env.secret
|
||||
```
|
||||
|
||||
<!--
|
||||
Note that in all cases, you don't need to base64 encode the values.
|
||||
-->
|
||||
注意,上面两种情况,你都不需要使用 base64 编码。
|
||||
|
||||
<!-- ## Create the Secret -->
|
||||
## 创建 Secret {#create-the-secret}
|
||||
|
||||
<!-- Apply the directory containing the `kustomization.yaml` to create the Secret. -->
|
||||
使用 `kubectl apply` 命令应用包含 `kustomization.yaml` 文件的目录创建 Secret。
|
||||
|
||||
```shell
|
||||
kubectl apply -k .
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
secret/db-user-pass-96mffmfh4k created
|
||||
```
|
||||
|
||||
<!--
|
||||
Note that when a Secret is generated, the Secret name is created by hashing
|
||||
the Secret data and appending the hash value to the name. This ensures that
|
||||
a new Secret is generated each time the data is modified.
|
||||
-->
|
||||
请注意,生成 Secret 时,Secret 的名称最终是由 `name` 字段和数据的哈希值拼接而成。
|
||||
这将保证每次修改数据时生成一个新的 Secret。
|
||||
|
||||
<!-- ## Check the Secret created -->
|
||||
## 检查创建的 Secret {#check-the-secret-created}
|
||||
|
||||
<!-- You can check that the secret was created: -->
|
||||
你可以检查刚才创建的 Secret:
|
||||
|
||||
```shell
|
||||
kubectl get secrets
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
NAME TYPE DATA AGE
|
||||
db-user-pass-96mffmfh4k Opaque 2 51s
|
||||
```
|
||||
|
||||
<!-- You can view a description of the secret: -->
|
||||
你可以看到 Secret 的描述:
|
||||
|
||||
```shell
|
||||
kubectl describe secrets/db-user-pass-96mffmfh4k
|
||||
```
|
||||
|
||||
<!-- The output is similar to: -->
|
||||
输出类似于:
|
||||
|
||||
```
|
||||
Name: db-user-pass-96mffmfh4k
|
||||
Namespace: default
|
||||
Labels: <none>
|
||||
Annotations: <none>
|
||||
|
||||
Type: Opaque
|
||||
|
||||
Data
|
||||
====
|
||||
password.txt: 12 bytes
|
||||
username.txt: 5 bytes
|
||||
```
|
||||
|
||||
<!--
|
||||
The commands `kubectl get` and `kubectl describe` avoid showing the contents of a `Secret` by
|
||||
default. This is to protect the `Secret` from being exposed accidentally to an onlooker,
|
||||
or from being stored in a terminal log.
|
||||
To check the actual content of the encoded data, please refer to
|
||||
[decoding secret](/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret).
|
||||
-->
|
||||
`kubectl get` 和 `kubectl describe` 命令默认不显示 `Secret` 的内容。
|
||||
这是为了防止 `Secret` 被意外暴露给旁观者或存储在终端日志中。
|
||||
检查编码后的实际内容,请参考[解码 secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kubectl/#decoding-secret)。
|
||||
-->
|
||||
|
||||
|
||||
<!-- ## Clean Up -->
|
||||
## 清理 {#clean-up}
|
||||
|
||||
<!-- To delete the Secret you have created: -->
|
||||
删除你创建的 Secret:
|
||||
|
||||
```shell
|
||||
kubectl delete secret db-user-pass-96mffmfh4k
|
||||
```
|
||||
|
||||
<!-- Optional section; add links to information related to this topic. -->
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
<!--
|
||||
- Read more about the [Secret concept](/docs/concepts/configuration/secret/)
|
||||
- Learn how to [manage Secrets with the `kubectl` command](/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
|
||||
- Learn how to [manage Secrets using config file](/docs/tasks/configmap-secret/managing-secret-using-config-file/)
|
||||
-->
|
||||
- 进一步阅读 [Secret 概念](/zh/docs/concepts/configuration/secret/)
|
||||
- 了解如何[使用 `kubectl` 命令管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-kubectl/)
|
||||
- 了解如何[使用配置文件管理 Secret](/zh/docs/tasks/configmap-secret/managing-secret-using-config-file/)
|
||||
Reference in New Issue
Block a user