[zh]Resync tasks files[11]
This commit is contained in:
+34
-15
@@ -39,18 +39,18 @@ that run in the Pod. To set environment variables, include the `env` or
|
||||
<!--
|
||||
In this exercise, you create a Pod that runs one container. The configuration
|
||||
file for the Pod defines an environment variable with name `DEMO_GREETING` and
|
||||
value `"Hello from the environment"`. Here is the configuration file for the
|
||||
value `"Hello from the environment"`. Here is the configuration manifest for the
|
||||
Pod:
|
||||
-->
|
||||
本示例中,将创建一个只包含单个容器的 Pod。Pod 的配置文件中设置环境变量的名称为 `DEMO_GREETING`,
|
||||
其值为 `"Hello from the environment"`。下面是 Pod 的配置文件内容:
|
||||
其值为 `"Hello from the environment"`。下面是 Pod 的配置清单:
|
||||
|
||||
{{< codenew file="pods/inject/envars.yaml" >}}
|
||||
|
||||
<!--
|
||||
1. Create a Pod based on the YAML configuration file:
|
||||
1. Create a Pod based on that manifest:
|
||||
-->
|
||||
1. 基于 YAML 文件创建一个 Pod:
|
||||
1. 基于配置清单创建一个 Pod:
|
||||
|
||||
```shell
|
||||
kubectl apply -f https://k8s.io/examples/pods/inject/envars.yaml
|
||||
@@ -59,7 +59,7 @@ Pod:
|
||||
<!--
|
||||
1. List the running Pods:
|
||||
-->
|
||||
1. 获取一下当前正在运行的 Pods 信息:
|
||||
2. 获取一下当前正在运行的 Pods 信息:
|
||||
|
||||
```shell
|
||||
kubectl get pods -l purpose=demonstrate-envars
|
||||
@@ -69,8 +69,8 @@ Pod:
|
||||
The output is similar to this:
|
||||
-->
|
||||
查询结果应为:
|
||||
|
||||
```shell
|
||||
|
||||
```
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
envar-demo 1/1 Running 0 9s
|
||||
```
|
||||
@@ -78,8 +78,8 @@ Pod:
|
||||
<!--
|
||||
1. List the Pod's container environment variables:
|
||||
-->
|
||||
1. 列出 Pod 容器的环境变量:
|
||||
|
||||
3. 列出 Pod 容器的环境变量:
|
||||
|
||||
```shell
|
||||
kubectl exec envar-demo -- printenv
|
||||
```
|
||||
@@ -88,8 +88,8 @@ Pod:
|
||||
The output is similar to this:
|
||||
-->
|
||||
打印结果应为:
|
||||
|
||||
```shell
|
||||
|
||||
```
|
||||
NODE_VERSION=4.4.2
|
||||
EXAMPLE_SERVICE_PORT_8080_TCP_ADDR=10.3.245.237
|
||||
HOSTNAME=envar-demo
|
||||
@@ -101,25 +101,44 @@ Pod:
|
||||
<!--
|
||||
{{< note >}}
|
||||
The environment variables set using the `env` or `envFrom` field
|
||||
will override any environment variables specified in the container image.
|
||||
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 >}}
|
||||
环境变量可以互相引用,但是顺序很重要。
|
||||
使用在相同上下文中定义的其他变量的变量必须在列表的后面。
|
||||
同样,请避免使用循环引用。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Using environment variables inside of your config
|
||||
|
||||
Environment variables that you define in a Pod's configuration can be used elsewhere in the configuration, for example in commands and arguments that you set for the Pod's containers. In the example configuration below, the `GREETING`, `HONORIFIC`, and `NAME` environment variables are set to `Warm greetings to`, `The Most Honorable`, and `Kubernetes`, respectively. Those environment variables are then used in the CLI arguments passed to the `env-print-demo` container.
|
||||
Environment variables that you define in a Pod's configuration can be used
|
||||
elsewhere in the configuration, for example in commands and arguments that
|
||||
you set for the Pod's containers.
|
||||
In the example configuration below, the `GREETING`, `HONORIFIC`, and
|
||||
`NAME` environment variables are set to `Warm greetings to`, `The Most
|
||||
Honorable`, and `Kubernetes`, respectively. Those environment variables
|
||||
are then used in the CLI arguments passed to the `env-print-demo`
|
||||
container.
|
||||
-->
|
||||
## 在配置中使用环境变量
|
||||
|
||||
您在 Pod 的配置中定义的环境变量可以在配置的其他地方使用,例如可用在为 Pod 的容器设置的命令和参数中。在下面的示例配置中,环境变量 `GREETING` ,`HONORIFIC` 和 `NAME` 分别设置为 `Warm greetings to` ,`The Most Honorable` 和 `Kubernetes`。然后这些环境变量在传递给容器 `env-print-demo` 的 CLI 参数中使用。
|
||||
您在 Pod 的配置中定义的环境变量可以在配置的其他地方使用,
|
||||
例如可用在为 Pod 的容器设置的命令和参数中。
|
||||
在下面的示例配置中,环境变量 `GREETING` ,`HONORIFIC` 和 `NAME` 分别设置为 `Warm greetings to` ,
|
||||
`The Most Honorable` 和 `Kubernetes`。然后这些环境变量在传递给容器 `env-print-demo` 的 CLI 参数中使用。
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
|
||||
Reference in New Issue
Block a user