Skip to content

Commit

Permalink
[zh] updated distribute-credentials-secure.md
Browse files Browse the repository at this point in the history
  • Loading branch information
windsonsea committed Oct 15, 2022
1 parent 3103ef6 commit b60cc12
Showing 1 changed file with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ min-kubernetes-server-version: v1.6
This page shows how to securely inject sensitive data, such as passwords and
encryption keys, into Pods.
-->
本文展示如何安全地将敏感数据(如密码和加密密钥)注入到 Pods 中。

本文展示如何安全地将敏感数据(如密码和加密密钥)注入到 Pod 中。

## {{% heading "prerequisites" %}}


{{< include "task-tutorial-prereqs.md" >}}


<!--
### Convert your secret data to a base-64 representation
Suppose you want to have two pieces of secret data: a username `my-app` and a password
`39528$vdg7Jb`. First, use a base64 encoding tool to convert your username and password to a base64 representation. Here's an example using the commonly available base64 program:
-->
### secret 数据转换为 base-64 形式
### Secret 数据转换为 base-64 形式 {#convert-your-secret-data-to-a-base64-representation}

假设用户想要有两条 Secret 数据:用户名 `my-app` 和密码 `39528$vdg7Jb`
首先使用 [Base64 编码](https://www.base64encode.org/) 将用户名和密码转化为 base-64 形式。
首先使用 [Base64 编码](https://www.base64encode.org/)将用户名和密码转化为 base-64 形式。
下面是一个使用常用的 base64 程序的示例:

```shell
Expand All @@ -43,10 +40,10 @@ and the base-64 representation of your password is `Mzk1MjgkdmRnN0pi`.
结果显示 base-64 形式的用户名为 `bXktYXBw`
base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`

{{< caution >}}
<!--
Use a local tool trusted by your OS to decrease the security risks of external tools.
-->
{{< caution >}}
使用你的操作系统所能信任的本地工具以降低使用外部工具的风险。
{{< /caution >}}

Expand All @@ -58,14 +55,16 @@ Use a local tool trusted by your OS to decrease the security risks of external t
Here is a configuration file you can use to create a Secret that holds your
username and password:
-->
## 创建 Secret
## 创建 Secret {#create-a-secret}

这里是一个配置文件,可以用来创建存有用户名和密码的 Secret:
这里是一个配置文件,可以用来创建存有用户名和密码的 Secret

{{< codenew file="pods/inject/secret.yaml" >}}

1. <!--Create the Secret -->
创建 Secret:
<!--
1. Create the Secret
-->
1. 创建 Secret:

```shell
kubectl apply -f https://k8s.io/examples/pods/inject/secret.yaml
Expand All @@ -78,24 +77,30 @@ username and password:

```shell
kubectl get secret test-secret
```
```

<!-- Output: -->
输出:
<!--
Output:
-->
输出:

```
NAME TYPE DATA AGE
test-secret Opaque 2 1m
```

1. <!-- View more detailed information about the Secret:-->
查看 Secret 相关的更多详细信息:
<!--
1. View more detailed information about the Secret:
-->
3. 查看 Secret 相关的更多详细信息:

```shell
kubectl describe secret test-secret
```

<!-- Output: -->
<!--
Output:
-->
输出:

```
Expand All @@ -118,7 +123,7 @@ username and password:
If you want to skip the Base64 encoding step, you can create the
same Secret using the `kubectl create secret` command. For example:
-->
### 直接用 kubectl 创建 Secret
### 直接用 kubectl 创建 Secret {#create-a-secret-directly-with-kubectl}

如果你希望略过 Base64 编码的步骤,你也可以使用 `kubectl create secret`
命令直接创建 Secret。例如:
Expand All @@ -134,15 +139,14 @@ through each step explicitly to demonstrate what is happening.
这是一种更为方便的方法。
前面展示的详细分解步骤有助于了解究竟发生了什么事情。


<!--
## Create a Pod that has access to the secret data through a Volume

Here is a configuration file you can use to create a Pod:
-->
## 创建一个可以通过卷访问 secret 数据的 Pod
## 创建一个可以通过卷访问 Secret 数据的 Pod {#create-a-pod-that-has-access-to-the-secret-data-through-a-volume}

这里是一个可以用来创建 pod 的配置文件:
这里是一个可以用来创建 Pod 的配置文件:

{{< codenew file="pods/inject/secret-pod.yaml" >}}

Expand All @@ -162,13 +166,14 @@ Here is a configuration file you can use to create a Pod:

<!-- Output: -->
输出:

```
NAME READY STATUS RESTARTS AGE
secret-test-pod 1/1 Running 0 42m
```

1. <!-- Get a shell into the Container that is running in your Pod:-->
获取一个 shell 进入 Pod 中运行的容器:
获取一个 Shell 进入 Pod 中运行的容器:

```shell
kubectl exec -i -t secret-test-pod -- /bin/bash
Expand All @@ -181,7 +186,7 @@ Here is a configuration file you can use to create a Pod:
-->
Secret 数据通过挂载在 `/etc/secret-volume` 目录下的卷暴露在容器中。

shell 中,列举 `/etc/secret-volume` 目录下的文件:
Shell 中,列举 `/etc/secret-volume` 目录下的文件:

```shell
# 在容器中 Shell 运行下面命令
Expand All @@ -201,6 +206,7 @@ Here is a configuration file you can use to create a Pod:
In your shell, display the contents of the `username` and `password` files:
-->
在 Shell 中,显示 `username``password` 文件的内容:

```shell
# 在容器中 Shell 运行下面命令
echo "$( cat /etc/secret-volume/username )"
Expand All @@ -223,9 +229,9 @@ Here is a configuration file you can use to create a Pod:
### Define a container environment variable with data from a single Secret

-->
## 使用 Secret 数据定义容器变量
## 使用 Secret 数据定义容器变量 {#define-container-env-var-using-secret-data}

### 使用来自 Secret 中的数据定义容器变量
### 使用来自 Secret 中的数据定义容器变量 {#define-a-container-env-var-with-data-from-a-single-secret}

<!--
* Define an environment variable as a key-value pair in a Secret:
Expand All @@ -239,7 +245,7 @@ Here is a configuration file you can use to create a Pod:
<!--
* Assign the `backend-username` value defined in the Secret to the `SECRET_USERNAME` environment variable in the Pod specification.
-->
* 在 Pod 规约中,将 Secret 中定义的值 `backend-username` 赋给 `SECRET_USERNAME` 环境变量
* 在 Pod 规约中,将 Secret 中定义的值 `backend-username` 赋给 `SECRET_USERNAME` 环境变量

{{< codenew file="pods/inject/pod-single-secret-env-variable.yaml" >}}

Expand Down Expand Up @@ -272,7 +278,7 @@ Here is a configuration file you can use to create a Pod:
<!--
### Define container environment variables with data from multiple Secrets
-->
### 使用来自多个 Secret 的数据定义环境变量
### 使用来自多个 Secret 的数据定义环境变量 {#define-container-env-var-with-data-from-multi-secrets}

<!--
* As with the previous example, create the Secrets first.
Expand Down Expand Up @@ -317,16 +323,15 @@ Here is a configuration file you can use to create a Pod:
BACKEND_USERNAME=backend-admin
```


<!--
## Configure all key-value pairs in a Secret as container environment variables
-->
## 将 Secret 中的所有键值偶对定义为环境变量
## 将 Secret 中的所有键值偶对定义为环境变量 {#configure-all-key-value-pairs-in-a-secret-as-container-env-var}

{{< note >}}
<!--
This functionality is available in Kubernetes v1.6 and later.
-->
{{< note >}}
此功能在 Kubernetes 1.6 版本之后可用。
{{< /note >}}

Expand Down Expand Up @@ -365,18 +370,20 @@ This functionality is available in Kubernetes v1.6 and later.
kubectl exec -i -t envfrom-secret -- /bin/sh -c 'echo "username: $username\npassword: $password\n"'
```
<!--
The output is
-->
<!--
The output is
-->
输出为:
```
username: my-app
password: 39528$vdg7Jb
```
<!-- ### References -->
### 参考
<!--
### References
-->
### 参考 {#references}
* [Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core)
* [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core)
Expand All @@ -389,6 +396,5 @@ This functionality is available in Kubernetes v1.6 and later.
* Learn about [Volumes](/docs/concepts/storage/volumes/).
-->
* 进一步了解 [Secret](/zh-cn/docs/concepts/configuration/secret/)。
* 了解 [Volumes](/zh-cn/docs/concepts/storage/volumes/)。
* 了解[卷](/zh-cn/docs/concepts/storage/volumes/)。

0 comments on commit b60cc12

Please sign in to comment.