[zh] updated define-environment-variable-container.md

pull/37317/head
windsonsea 2022-10-15 21:54:31 +08:00
parent 3103ef6fba
commit 65d8604762
1 changed files with 10 additions and 15 deletions

View File

@ -16,7 +16,7 @@ weight: 20
This page shows how to define environment variables for a container
in a Kubernetes Pod.
-->
本页将展示如何为 kubernetes Pod 下的容器设置环境变量。
本页将展示如何为 Kubernetes Pod 下的容器设置环境变量。
## {{% heading "prerequisites" %}}
@ -27,7 +27,7 @@ in a Kubernetes Pod.
<!--
## Define an environment variable for a container
-->
## 为容器设置一个环境变量
## 为容器设置一个环境变量 {#define-an-env-variable-for-a-container}
<!--
When you create a Pod, you can set environment variables for the containers
@ -42,8 +42,8 @@ file for the Pod defines an environment variable with name `DEMO_GREETING` and
value `"Hello from the environment"`. Here is the configuration manifest for the
Pod:
-->
本示例中,将创建一个只包含单个容器的 Pod。Pod 的配置文件中设置环境变量的名称为 `DEMO_GREETING`
其值为 `"Hello from the environment"`。下面是 Pod 的配置清单:
本示例中,将创建一个只包含单个容器的 Pod。Pod 的配置文件中设置环境变量的名称为 `DEMO_GREETING`
其值为 `"Hello from the environment"`。下面是 Pod 的配置清单:
{{< codenew file="pods/inject/envars.yaml" >}}
@ -59,7 +59,7 @@ Pod:
<!--
1. List the running Pods:
-->
2. 获取一下当前正在运行的 Pods 信息:
2. 获取正在运行的 Pod 信息:
```shell
kubectl get pods -l purpose=demonstrate-envars
@ -98,24 +98,20 @@ Pod:
DEMO_FAREWELL=Such a sweet sorrow
```
<!--
{{< note >}}
<!--
The environment variables set using the `env` or `envFrom` field
override any environment variables specified in the container image.
{{< /note >}}
-->
{{< note >}}
通过 `env``envFrom` 字段设置的环境变量将覆盖容器镜像中指定的所有环境变量。
{{< /note >}}
<!--
{{< note >}}
<!--
Environment variables may reference each other, however ordering is important.
Variables making use of others defined in the same context must come later in
the list. Similarly, avoid circular references.
{{< /note >}}
-->
{{< note >}}
环境变量可以互相引用,但是顺序很重要。
使用在相同上下文中定义的其他变量的变量必须在列表的后面。
同样,请避免使用循环引用。
@ -133,11 +129,11 @@ Honorable`, and `Kubernetes`, respectively. Those environment variables
are then used in the CLI arguments passed to the `env-print-demo`
container.
-->
## 在配置中使用环境变量
## 在配置中使用环境变量 {#using-env-var-inside-of-your-config}
你在 Pod 的配置中定义的环境变量可以在配置的其他地方使用,
例如可用在为 Pod 的容器设置的命令和参数中。
在下面的示例配置中,环境变量 `GREETING` `HONORIFIC` 和 `NAME` 分别设置为 `Warm greetings to`
在下面的示例配置中,环境变量 `GREETING`、`HONORIFIC` 和 `NAME` 分别设置为 `Warm greetings to`
`The Most Honorable``Kubernetes`。然后这些环境变量在传递给容器 `env-print-demo` 的 CLI 参数中使用。
```yaml
@ -169,10 +165,9 @@ Upon creation, the command `echo Warm greetings to The Most Honorable Kubernetes
<!--
* Learn more about [environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/).
* Learn about [using secrets as environment variables](/docs/user-guide/secrets/#using-secrets-as-environment-variables).
* Learn about [using secrets as environment variables](/docs/concepts/configuration/secret/#using-secrets-as-environment-variables).
* See [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core).
-->
* 进一步了解[环境变量](/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information/)
* 进一步了解[通过环境变量来使用 Secret](/zh-cn/docs/concepts/configuration/secret/#using-secrets-as-environment-variables)
* 关于 [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core) 资源的信息。