From b60cc1202b1cba5aeaa9886c54b823225f240a52 Mon Sep 17 00:00:00 2001 From: windsonsea Date: Sat, 15 Oct 2022 22:26:16 +0800 Subject: [PATCH] [zh] updated distribute-credentials-secure.md --- .../distribute-credentials-secure.md | 80 ++++++++++--------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/content/zh-cn/docs/tasks/inject-data-application/distribute-credentials-secure.md b/content/zh-cn/docs/tasks/inject-data-application/distribute-credentials-secure.md index 0a07cf1094..b5755b6d4a 100644 --- a/content/zh-cn/docs/tasks/inject-data-application/distribute-credentials-secure.md +++ b/content/zh-cn/docs/tasks/inject-data-application/distribute-credentials-secure.md @@ -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" >}} - -### 将 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 @@ -43,10 +40,10 @@ and the base-64 representation of your password is `Mzk1MjgkdmRnN0pi`. 结果显示 base-64 形式的用户名为 `bXktYXBw`, base-64 形式的密码为 `Mzk1MjgkdmRnN0pi`。 +{{< caution >}} -{{< caution >}} 使用你的操作系统所能信任的本地工具以降低使用外部工具的风险。 {{< /caution >}} @@ -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. - 创建 Secret: + +1. 创建 Secret: ```shell kubectl apply -f https://k8s.io/examples/pods/inject/secret.yaml @@ -78,24 +77,30 @@ username and password: ```shell kubectl get secret test-secret - ``` + ``` - - 输出: + + 输出: ``` NAME TYPE DATA AGE test-secret Opaque 2 1m ``` -1. - 查看 Secret 相关的更多详细信息: + +3. 查看 Secret 相关的更多详细信息: ```shell kubectl describe secret test-secret ``` - + 输出: ``` @@ -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。例如: @@ -134,15 +139,14 @@ through each step explicitly to demonstrate what is happening. 这是一种更为方便的方法。 前面展示的详细分解步骤有助于了解究竟发生了什么事情。 - -## 创建一个可以通过卷访问 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" >}} @@ -162,13 +166,14 @@ Here is a configuration file you can use to create a Pod: 输出: + ``` NAME READY STATUS RESTARTS AGE secret-test-pod 1/1 Running 0 42m ``` 1. - 获取一个 shell 进入 Pod 中运行的容器: + 获取一个 Shell 进入 Pod 中运行的容器: ```shell kubectl exec -i -t secret-test-pod -- /bin/bash @@ -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 运行下面命令 @@ -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 )" @@ -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} -* 在 Pod 规约中,将 Secret 中定义的值 `backend-username` 赋给 `SECRET_USERNAME` 环境变量 +* 在 Pod 规约中,将 Secret 中定义的值 `backend-username` 赋给 `SECRET_USERNAME` 环境变量。 {{< codenew file="pods/inject/pod-single-secret-env-variable.yaml" >}} @@ -272,7 +278,7 @@ Here is a configuration file you can use to create a Pod: -### 使用来自多个 Secret 的数据定义环境变量 +### 使用来自多个 Secret 的数据定义环境变量 {#define-container-env-var-with-data-from-multi-secrets} -## 将 Secret 中的所有键值偶对定义为环境变量 +## 将 Secret 中的所有键值偶对定义为环境变量 {#configure-all-key-value-pairs-in-a-secret-as-container-env-var} +{{< note >}} -{{< note >}} 此功能在 Kubernetes 1.6 版本之后可用。 {{< /note >}} @@ -365,9 +370,9 @@ 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"' ``` - + 输出为: ``` @@ -375,8 +380,10 @@ This functionality is available in Kubernetes v1.6 and later. password: 39528$vdg7Jb ``` - -### 参考 + +### 参考 {#references} * [Secret](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#secret-v1-core) * [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core) @@ -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/)。