Skip to content

Commit 0b99c6a

Browse files
authored
Merge pull request #36755 from windsonsea/defenv
[zh]Resync define-interdependent-environment-variables.md
2 parents 1a3da6b + c354a32 commit 0b99c6a

File tree

1 file changed

+47
-33
lines changed

1 file changed

+47
-33
lines changed

content/zh-cn/docs/tasks/inject-data-application/define-interdependent-environment-variables.md

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ in a Kubernetes Pod.
1717

1818
## {{% heading "prerequisites" %}}
1919

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

23-
2422
<!-- steps -->
2523

2624
<!--
@@ -34,46 +32,54 @@ Pod:
3432
-->
3533
## 为容器定义相互依赖的环境变量 {#define-an-environment-dependent-variable-for-a-container}
3634

37-
当创建一个 Pod 时,你可以为运行在 Pod 中的容器设置相互依赖的环境变量。
38-
设置相互依赖的环境变量,你就可以在配置清单文件的 `env``value` 中使用 $(VAR_NAME)。
35+
当创建一个 Pod 时,你可以为运行在 Pod 中的容器设置相互依赖的环境变量。
36+
若要设置相互依赖的环境变量,你可以在配置清单文件的 `env``value` 中使用 $(VAR_NAME)。
3937

4038
在本练习中,你会创建一个单容器的 Pod。
4139
此 Pod 的配置文件定义了一个已定义常用用法的相互依赖的环境变量。
42-
下面是 Pod 的配置清单:
40+
下面是此 Pod 的配置清单:
4341

4442
{{< codenew file="pods/inject/dependent-envars.yaml" >}}
4543

46-
<!-- 1. Create a Pod based on that manifest: -->
44+
<!--
45+
1. Create a Pod based on that manifest:
46+
-->
4747
1. 依据清单创建 Pod:
48-
```shell
49-
kubectl apply -f https://k8s.io/examples/pods/inject/dependent-envars.yaml
50-
```
51-
```
52-
pod/dependent-envars-demo created
53-
```
54-
<!-- 2. List the running Pods: -->
48+
49+
```shell
50+
kubectl apply -f https://k8s.io/examples/pods/inject/dependent-envars.yaml
51+
```
52+
```
53+
pod/dependent-envars-demo created
54+
```
55+
56+
<!--
57+
2. List the running Pods:
58+
-->
5559
2. 列出运行的 Pod:
5660

57-
```shell
58-
kubectl get pods dependent-envars-demo
59-
```
60-
```
61-
NAME READY STATUS RESTARTS AGE
62-
dependent-envars-demo 1/1 Running 0 9s
63-
```
61+
```shell
62+
kubectl get pods dependent-envars-demo
63+
```
64+
```
65+
NAME READY STATUS RESTARTS AGE
66+
dependent-envars-demo 1/1 Running 0 9s
67+
```
6468

65-
<!-- 3. Check the logs for the container running in your Pod: -->
69+
<!--
70+
3. Check the logs for the container running in your Pod:
71+
-->
6672
3. 检查 Pod 中运行容器的日志:
6773

68-
```shell
69-
kubectl logs pod/dependent-envars-demo
70-
```
71-
```
74+
```shell
75+
kubectl logs pod/dependent-envars-demo
76+
```
77+
```
7278
73-
UNCHANGED_REFERENCE=$(PROTOCOL)://172.17.0.1:80
74-
SERVICE_ADDRESS=https://172.17.0.1:80
75-
ESCAPED_REFERENCE=$(PROTOCOL)://172.17.0.1:80
76-
```
79+
UNCHANGED_REFERENCE=$(PROTOCOL)://172.17.0.1:80
80+
SERVICE_ADDRESS=https://172.17.0.1:80
81+
ESCAPED_REFERENCE=$(PROTOCOL)://172.17.0.1:80
82+
```
7783

7884
<!--
7985
As shown above, you have defined the correct dependency reference of `SERVICE_ADDRESS`, bad dependency reference of `UNCHANGED_REFERENCE` and skip dependent references of `ESCAPED_REFERENCE`.
@@ -88,6 +94,15 @@ the reference can be correctly resolved, such as in the `SERVICE_ADDRESS` case.
8894
如果环境变量被引用时已事先定义,则引用可以正确解析,
8995
比如 `SERVICE_ADDRESS` 的例子。
9096

97+
<!--
98+
Note that order matters in the `env` list. An environment variable is not considered
99+
"defined" if it is specified further down the list. That is why `UNCHANGED_REFERENCE`
100+
fails to resolve `$(PROTOCOL)` in the example above.
101+
-->
102+
请注意,`env` 列表中的顺序很重要。如果某环境变量定义出现在列表的尾部,
103+
则在解析列表前部环境变量时不会视其为“已被定义”。
104+
这就是为什么 `UNCHANGED_REFERENCE` 在上面的示例中解析 `$(PROTOCOL)` 失败的原因。
105+
91106
<!--
92107
When the environment variable is undefined or only includes some variables, the undefined environment variable is treated as a normal string, such as `UNCHANGED_REFERENCE`. Note that incorrectly parsed environment variables, in general, will not block the container from starting.
93108
@@ -99,17 +114,16 @@ is defined or not. This can be seen from the `ESCAPED_REFERENCE` case above.
99114
比如 `UNCHANGED_REFERENCE` 的例子。
100115
注意,解析不正确的环境变量通常不会阻止容器启动。
101116

102-
`$(VAR_NAME)` 这样的语法可以用两个 `$` 转义,`$$(VAR_NAME)`
117+
`$(VAR_NAME)` 这样的语法可以用两个 `$` 转义,`$$(VAR_NAME)`
103118
无论引用的变量是否定义,转义的引用永远不会展开。
104119
这一点可以从上面 `ESCAPED_REFERENCE` 的例子得到印证。
105120

106121
## {{% heading "whatsnext" %}}
107122

108-
109123
<!--
110124
* Learn more about [environment variables](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/).
111125
* See [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core).
112126
-->
113-
* 进一步了解[环境变量](/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information/).
114-
* 参阅 [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core).
127+
* 进一步了解[环境变量](/zh-cn/docs/tasks/inject-data-application/environment-variable-expose-pod-information/)
128+
* 参阅 [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core)
115129

0 commit comments

Comments
 (0)