[zh] Tidy up and fix links in tasks section (10/10)

pull/23201/head
Qiming Teng 2020-08-16 20:50:27 +08:00
parent fb6364da0a
commit 114a75d78d
3 changed files with 197 additions and 127 deletions

View File

@ -1,14 +1,12 @@
---
title: 为容器设置启动时要执行的命令及其入参
title: 为容器设置启动时要执行的命令和参数
content_type: task
weight: 10
---
<!--
---
title: Define a Command and Arguments for a Container
content_type: task
weight: 10
---
-->
<!-- overview -->
@ -17,34 +15,27 @@ weight: 10
This page shows how to define commands and arguments when you run a container
in a {{< glossary_tooltip term_id="pod" >}}.
-->
本页将展示如何为 {{< glossary_tooltip term_id="pod" >}} 中的容器设置启动时要执行的命令及其入参。
本页将展示如何为 {{< glossary_tooltip text="Pod" term_id="pod" >}}
中容器设置启动时要执行的命令及其参数。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
<!-- steps -->
<!--
## Define a command and arguments when you create a Pod
-->
## 创建 Pod 时设置命令及入参
<!--
When you create a Pod, you can define a command and arguments for the
containers that run in the Pod. To define a command, include the `command`
field in the configuration file. To define arguments for the command, include
the `args` field in the configuration file. The command and arguments that
you define cannot be changed after the Pod is created.
-->
创建 Pod 时,可以为其下的容器设置启动时要执行的命令及其入参。如果要设置命令,就填写在配置文件的 `command` 字段下,如果要设置命令的入参,就填写在配置文件的 `args` 字段下。一旦 Pod 创建完成,该命令及其入参就无法再进行更改了。
## 创建 Pod 时设置命令及参数
创建 Pod 时,可以为其下的容器设置启动时要执行的命令及其参数。如果要设置命令,就填写在配置文件的 `command` 字段下,如果要设置命令的参数,就填写在配置文件的 `args` 字段下。一旦 Pod 创建完成,该命令及其参数就无法再进行更改了。
<!--
The command and arguments that you define in the configuration file
@ -52,23 +43,22 @@ override the default command and arguments provided by the container image.
If you define args, but do not define a command, the default command is used
with your new arguments.
-->
如果在配置文件中设置了容器启动时要执行的命令及其参,那么容器镜像中自带的命令与参将会被覆盖而不再执行。如果配置文件中只是设置了参,却没有设置其对应的命令,那么容器镜像中自带的命令会使用该新参作为其执行时的参。
如果在配置文件中设置了容器启动时要执行的命令及其参,那么容器镜像中自带的命令与参将会被覆盖而不再执行。如果配置文件中只是设置了参,却没有设置其对应的命令,那么容器镜像中自带的命令会使用该新参作为其执行时的参
<!--
{{< note >}}
The `command` field corresponds to `entrypoint` in some container
runtimes. Refer to the [Notes](#notes) below.
{{< /note >}}
-->
{{< note >}}
在有些容器运行时中,`command` 字段对应 `entrypoint`,请参阅下面的 [注意](#注意)。
在有些容器运行时中,`command` 字段对应 `entrypoint`,请参阅下面的
[说明事项](#notes)。
{{< /note >}}
<!--
In this exercise, you create a Pod that runs one container. The configuration
file for the Pod defines a command and two arguments:
-->
本示例中,将创建一个只包含单个容器的 Pod。在 Pod 配置文件中设置了一个命令与两个参:
本示例中,将创建一个只包含单个容器的 Pod。在 Pod 配置文件中设置了一个命令与两个参
{{< codenew file="pods/commands.yaml" >}}
@ -77,23 +67,23 @@ file for the Pod defines a command and two arguments:
-->
1. 基于 YAML 文件创建一个 Pod
```shell
kubectl apply -f https://k8s.io/examples/pods/commands.yaml
```
```shell
kubectl apply -f https://k8s.io/examples/pods/commands.yaml
```
<!--
1. List the running Pods:
-->
2. 获取正在运行的 Pods
```shell
kubectl get pods
```
```shell
kubectl get pods
```
<!--
The output shows that the container that ran in the command-demo Pod has completed.
-->
查询结果显示在 command-demo 这个 Pod 下运行的容器已经启动完成。
<!--
The output shows that the container that ran in the command-demo Pod has completed.
-->
查询结果显示在 command-demo 这个 Pod 下运行的容器已经启动完成。
<!--
1. To see the output of the command that ran in the container, view the logs
@ -101,19 +91,19 @@ from the Pod:
-->
3. 如果要获取容器启动时执行命令的输出结果,可以通过 Pod 的日志进行查看:
```shell
kubectl logs command-demo
```
```shell
kubectl logs command-demo
```
<!--
The output shows the values of the HOSTNAME and KUBERNETES_PORT environment variables:
-->
日志中显示了 HOSTNAME 与 KUBERNETES_PORT 这两个环境变量的值:
```
command-demo
tcp://10.3.240.1:443
```
<!--
The output shows the values of the HOSTNAME and KUBERNETES_PORT environment variables:
-->
日志中显示了 HOSTNAME 与 KUBERNETES_PORT 这两个环境变量的值:
```
command-demo
tcp://10.3.240.1:443
```
<!--
## Use environment variables to define arguments
@ -122,9 +112,9 @@ In the preceding example, you defined the arguments directly by
providing strings. As an alternative to providing strings directly,
you can define arguments by using environment variables:
-->
## 使用环境变量来设置
## 使用环境变量来设置参
在上面的示例中,我们直接将一串字符作为命令的参。除此之外,我们还可以将环境变量作为命令的参。
在上面的示例中,我们直接将一串字符作为命令的参。除此之外,我们还可以将环境变量作为命令的参
```yaml
env:
@ -141,13 +131,13 @@ the techniques available for defining environment variables, including
and
[Secrets](/docs/concepts/configuration/secret/).
-->
这意味着你可以将那些用来设置环境变量的方法应用于设置命令的入参,其中包括了 [ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/) 与 [Secrets](/docs/concepts/configuration/secret/)。
这意味着你可以将那些用来设置环境变量的方法应用于设置命令的参数,其中包括了
[ConfigMaps](/zh/docs/tasks/configure-pod-container/configure-pod-configmap/) 与
[Secrets](/zh/docs/concepts/configuration/secret/)。
<!--
{{< note >}}
The environment variable appears in parentheses, `"$(VAR)"`. This is
required for the variable to be expanded in the `command` or `args` field.
{{< /note >}}
-->
{{< note >}}
环境变量需要加上括号,类似于 `"$(VAR)"`。这是在 `command``args` 字段使用变量的格式要求。
@ -160,9 +150,11 @@ In some cases, you need your command to run in a shell. For example, your
command might consist of several commands piped together, or it might be a shell
script. To run your command in a shell, wrap it like this:
-->
## 通过 shell 来执行命令
## 在 Shell 来执行命令
有时候,您需要在 shell 脚本中运行命令。 例如,您要执行的命令可能由多个命令组合而成,或者它就是一个 shell 脚本。这时,就可以通过如下方式在 shell 中执行命令:
有时候,你需要在 Shell 脚本中运行命令。
例如,你要执行的命令可能由多个命令组合而成,或者它就是一个 Shell 脚本。
这时,就可以通过如下方式在 Shell 中执行命令:
```shell
command: ["/bin/sh"]
@ -175,16 +167,16 @@ args: ["-c", "while true; do echo hello; sleep 10;done"]
This table summarizes the field names used by Docker and Kubernetes.
| Description | Docker field name | Kubernetes field name |
|----------------------------------------|------------------------|-----------------------|
| The command run by the container | Entrypoint | command |
| The arguments passed to the command | Cmd | args |
|----------------------------------------|------------------------|---------------------|
| The command run by the container | Entrypoint | command |
| The arguments passed to the command | Cmd | args |
-->
## 注意
## 说明事项 {#notes}
下表给出了 Docker 与 Kubernetes 中对应的字段名称。
| 描述 | Docker 字段名称 | Kubernetes 字段名称 |
|------------------|--------------------|-----------------------|
| 描述 | Docker 字段名称 | Kubernetes 字段名称 |
|--------------------|--------------------|-----------------------|
| 容器执行的命令 | Entrypoint | command |
| 传给命令的参数 | Cmd | args |
@ -207,13 +199,15 @@ Cmd defined in the Docker image are ignored. Your `command` is run with your
-->
如果要覆盖默认的 Entrypoint 与 Cmd需要遵循如下规则
* 如果在容器配置中没有设置 `command` 或者 `args`,那么将使用 Docker 镜像自带的命令及其参。
* 如果在容器配置中没有设置 `command` 或者 `args`,那么将使用 Docker 镜像自带的命令及其参
* 如果在容器配置中只设置了 `command` 但是没有设置 `args`那么容器启动时只会执行该命令Docker 镜像中自带的命令及其入参会被忽略。
* 如果在容器配置中只设置了 `command` 但是没有设置 `args`,那么容器启动时只会执行该命令,
Docker 镜像中自带的命令及其参数会被忽略。
* 如果在容器配置中只设置了 `args`,那么 Docker 镜像中自带的命令会使用该新参作为其执行时的参。
* 如果在容器配置中只设置了 `args`,那么 Docker 镜像中自带的命令会使用该新参作为其执行时的参
* 如果在容器配置中同时设置了 `command``args`,那么 Docker 镜像中自带的命令及其入参会被忽略。容器启动时只会执行配置中设置的命令,并使用配置中设置的入参作为命令的入参。
* 如果在容器配置中同时设置了 `command``args`,那么 Docker 镜像中自带的命令及其参数会被忽略。
容器启动时只会执行配置中设置的命令,并使用配置中设置的参数作为命令的参数。
<!--
Here are some examples:
@ -225,9 +219,9 @@ Here are some examples:
| `[/ep-1]` | `[foo bar]` | &lt;not set&gt; | `[zoo boo]` | `[ep-1 zoo boo]` |
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | `[zoo boo]` | `[ep-2 zoo boo]` |
-->
表涵盖了各类设置场景
面是一些例子
| 镜像 Entrypoint | 镜像 Cmd | 容器 command | 容器 args | 命令执行 |
| 镜像 Entrypoint | 镜像 Cmd | 容器 command | 容器 args | 命令执行 |
|--------------------|------------------|---------------------|--------------------|------------------|
| `[/ep-1]` | `[foo bar]` | &lt;not set&gt; | &lt;not set&gt; | `[ep-1 foo bar]` |
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | &lt;not set&gt; | `[ep-2]` |
@ -235,21 +229,15 @@ Here are some examples:
| `[/ep-1]` | `[foo bar]` | `[/ep-2]` | `[zoo boo]` | `[ep-2 zoo boo]` |
## {{% heading "whatsnext" %}}
<!--
* Learn more about [configuring pods and containers](/docs/tasks/).
* Learn more about [running commands in a container](/docs/tasks/debug-application-cluster/get-shell-running-container/).
* See [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core).
-->
* 了解更多 [pod 和容器的配置](/docs/tasks/)。
* 了解更多 [在容器中运行命令](/docs/tasks/debug-application-cluster/get-shell-running-container/)。
* 请参阅 [有关容器的文档](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)。
* 进一步了解[配置 Pod 和容器](/zh/docs/tasks/)
* 进一步了解[在容器中运行命令](/zh/docs/tasks/debug-application-cluster/get-shell-running-container/)
* 参阅 [Container](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#container-v1-core)
API 资源

View File

@ -1,14 +1,13 @@
---
title: 为容器设置环境变量
content_type: task
weight: 20
---
<!--
---
title: Define Environment Variables for a Container
content_type: task
weight: 20
---
-->
<!-- overview -->
@ -17,26 +16,17 @@ weight: 20
This page shows how to define environment variables for a container
in a Kubernetes Pod.
-->
本页将展示如何为 kubernetes Pod 下的容器设置环境变量。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
{{< include "task-tutorial-prereqs.md" >}}
<!-- steps -->
<!--
## Define an environment variable for a container
-->
## 为容器设置一个环境变量
<!--
@ -44,7 +34,6 @@ When you create a Pod, you can set environment variables for the containers
that run in the Pod. To set environment variables, include the `env` or
`envFrom` field in the configuration file.
-->
创建 Pod 时,可以为其下的容器设置环境变量。通过配置文件的 `env` 或者 `envFrom` 字段来设置环境变量。
<!--
@ -53,7 +42,6 @@ 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
Pod:
-->
本示例中,将创建一个只包含单个容器的 Pod。Pod 的配置文件中设置环境变量的名称为 `DEMO_GREETING`
其值为 `"Hello from the environment"`。下面是 Pod 的配置文件内容:
@ -172,19 +160,15 @@ Upon creation, the command `echo Warm greetings to The Most Honorable Kubernetes
-->
创建后,命令 `echo Warm greetings to The Most Honorable Kubernetes` 将在容器中运行。
## {{% heading "whatsnext" %}}
<!--
* 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).
* See [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core).
-->
* 有关环境变量的更多信息,请参阅[这里](/docs/tasks/inject-data-application/environment-variable-expose-pod-information/)
* 有关如何通过环境变量来使用 Secret请参阅[这里](/docs/user-guide/secrets/#using-secrets-as-environment-variables)。
* 进一步了解[环境变量](/zh/docs/tasks/inject-data-application/environment-variable-expose-pod-information/)
* 进一步了解[通过环境变量来使用 Secret](/zh/docs/concepts/configuration/secret/#using-secrets-as-environment-variables)
* 关于 [EnvVarSource](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#envvarsource-v1-core) 资源的信息。

View File

@ -3,29 +3,48 @@ approvers:
- janetkuo
title: 对 DaemonSet 执行回滚
content_type: task
weight: 20
min-kubernetes-server-version: 1.7
---
<!--
reviewers:
- janetkuo
title: Perform a Rollback on a DaemonSet
content_type: task
weight: 20
min-kubernetes-server-version: 1.7
-->
<!-- overview -->
本文展示了如何对 DaemonSet 执行回滚。
<!--
This page shows how to perform a rollback on a {{< glossary_tooltip term_id="daemonset" >}}.
-->
本文展示了如何对 {{< glossary_tooltip term_id="daemonset" text="DaemonSet" >}} 执行回滚。
## {{% heading "prerequisites" %}}
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
* DaemonSet 滚动升级历史和 DaemonSet 回滚特性仅在 Kubernetes 1.7 及以后版本的 `kubectl` 中支持。
* 确保您了解如何 [对 DaemonSet 执行滚动升级](/docs/tasks/manage-daemon/update-daemon-set/)。
<!--
You should already know how to [perform a rolling update on a
DaemonSet](/docs/tasks/manage-daemon/update-daemon-set/).
-->
你应该已经了解如何[为 DaemonSet 执行滚东更新](/zh/docs/tasks/manage-daemon/update-daemon-set/)。
<!-- steps -->
<!--
## Performing a rollback on a DaemonSet
### Step 1: Find the DaemonSet revision you want to roll back to
You can skip this step if you just want to roll back to the last revision.
List all revisions of a DaemonSet:
-->
## 对 DaemonSet 执行回滚
### 步骤 1 找到想要 DaemonSet 回滚到的历史版本revision
### 步骤 1找到想要 DaemonSet 回滚到的历史修订版本revision
如果只想回滚到最后一个版本,可以跳过这一步。
@ -35,7 +54,10 @@ content_type: task
kubectl rollout history daemonset <daemonset-name>
```
该命令返回 DaemonSet 版本列表:
<!--
This returns a list of DaemonSet revisions:
-->
此命令返回 DaemonSet 版本列表:
```shell
daemonsets "<daemonset-name>"
@ -45,7 +67,16 @@ REVISION CHANGE-CAUSE
...
```
* 在创建时DaemonSet 的变化原因从 `kubernetes.io/change-cause` 注解annotation复制到其版本中。 用户可以在 `kubectl` 中指定 `--record=true` ,将执行的命令记录在变化原因注解中。
<!--
* Change cause is copied from DaemonSet annotation `kubernetes.io/change-cause`
to its revisions upon creation. You may specify `-record=true` in `kubectl`
to record the command executed in the change cause annotation.
To see the details of a specific revision:
-->
* 在创建时DaemonSet 的变化原因从 `kubernetes.io/change-cause` 注解annotation
复制到其修订版本中。用户可以在 `kubectl` 命令中设置 `--record=true`
将执行的命令记录在变化原因注解中。
执行以下命令,来查看指定版本的详细信息:
@ -53,7 +84,10 @@ REVISION CHANGE-CAUSE
kubectl rollout history daemonset <daemonset-name> --revision=1
```
该命令返回相应版本的详细信息:
<!--
This returns the details of that revision:
-->
该命令返回相应修订版本的详细信息:
```shell
daemonsets "<daemonset-name>" with revision #1
@ -68,73 +102,137 @@ app:
Volumes: ...
```
### 步骤 2 回滚到指定版本
<!--
### Step 2: Roll back to a specific revision
-->
### 步骤 2回滚到指定版本
```shell
# 在 --to-revision 中指定您从步骤 1 中获取的版本序号
# 在 --to-revision 中指定你从步骤 1 中获取的修订版本
kubectl rollout undo daemonset <daemonset-name> --to-revision=<revision>
```
<!--
If it succeeds, the command returns:
-->
如果成功,命令会返回:
```shell
daemonset "<daemonset-name>" rolled back
```
<!--
If `--to-revision` flag is not specified, kubectl picks the most recent revision.
-->
{{< note >}}
如果 `--to-revision` 参数未指定,将选中最近的版本。
{{< /note >}}
### 步骤 3 观察 DaemonSet 回滚进度
<!--
### Step 3: Watch the progress of the DaemonSet rollback
`kubectl rollout undo daemonset` 向服务器表明启动 DaemonSet 回滚。 真正的回滚是在服务器端异步完成的。
`kubectl rollout undo daemonset` tells the server to start rolling back the
DaemonSet. The real rollback is done asynchronously inside the cluster
{{< glossary_tooltip term_id="control-plane" text="control plane" >}}.
-->
### 步骤 3监视 DaemonSet 回滚进度
执行以下命令,来观察 DaemonSet 回滚进度:
`kubectl rollout undo daemonset` 向服务器表明启动 DaemonSet 回滚。
真正的回滚是在集群的
{{< glossary_tooltip term_id="control-plane" text="控制面" >}}
异步完成的。
<!--
To watch the progress of the rollback:
-->
执行以下命令,来监视 DaemonSet 回滚进度:
```shell
kubectl rollout status ds/<daemonset-name>
```
<!--
When the rollback is complete, the output is similar to:
-->
回滚完成时,输出形如:
```shell
```
daemonset "<daemonset-name>" successfully rolled out
```
<!-- discussion -->
## 理解 DaemonSet 版本
<!--
## Understanding DaemonSet revisions
在前面的 `kubectl rollout history` 步骤中,您获得了一个版本列表,每个版本都存储在名为
`ControllerRevision` 的资源中。 `ControllerRevision` 仅在 Kubernetes 1.7 及以后的版本中可用。
In the previous `kubectl rollout history` step, you got a list of DaemonSet
revisions. Each revision is stored in a resource named ControllerRevision.
查找原始的版本资源,来查看每个版本中存储了什么内容:
To see what is stored in each revision, find the DaemonSet revision raw
resources:
-->
## 理解 DaemonSet 修订版本
在前面的 `kubectl rollout history` 步骤中,你获得了一个修订版本列表,每个修订版本都存储在名为
`ControllerRevision` 的资源中。
要查看每个修订版本中保存的内容,可以找到 DaemonSet 修订版本的原生资源:
```shell
kubectl get controllerrevision -l <daemonset-selector-key>=<daemonset-selector-value>
```
<!--
This returns a list of ControllerRevisions:
-->
该命令返回 `ControllerRevisions` 列表:
```shell
```
NAME CONTROLLER REVISION AGE
<daemonset-name>-<revision-hash> DaemonSet/<daemonset-name> 1 1h
<daemonset-name>-<revision-hash> DaemonSet/<daemonset-name> 2 1h
```
<!--
Each ControllerRevision stores the annotations and template of a DaemonSet
revision.
-->
每个 `ControllerRevision` 中存储了相应 DaemonSet 版本的注解和模板。
`kubectl rollout undo` 采用特定 `ControllerRevision` ,并用
<!--
`kubectl rollout undo` takes a specific ControllerRevision and replaces
DaemonSet template with the template stored in the ControllerRevision.
`kubectl rollout undo` is equivalent to updating DaemonSet template to a
previous revision through other commands, such as `kubectl edit` or `kubectl
apply`.
-->
`kubectl rollout undo` 选择特定的 `ControllerRevision`,并用
`ControllerRevision` 中存储的模板代替 DaemonSet 的模板。
`kubectl rollout undo` 相当于通过其他命令(如 `kubectl edit``kubectl apply`)将 DaemonSet 模板更新至先前的版本。
`kubectl rollout undo` 相当于通过其他命令(如 `kubectl edit``kubectl apply`
将 DaemonSet 模板更新至先前的版本。
注意 DaemonSet 版本只会向前滚动。 也就是说,回滚完成后,所回滚到的 `ControllerRevision` 版本号 (`.revision` 字段) 会增加。 例如,如果用户在系统中有版本 1 和版本 2并从版本 2 回滚到版本 1 ,带有 `.revision: 1` 的`ControllerRevision` 将变为 `.revision: 3`
## 故障排除
* 查看 [DaemonSet 滚动升级故障排除](/docs/tasks/manage-daemon/update-daemon-set/#troubleshooting)。
<!--
DaemonSet revisions only roll forward. That is to say, after a
rollback completes, the revision number (`.revision` field) of the
ControllerRevision being rolled back to will advance. For example, if you
have revision 1 and 2 in the system, and roll back from revision 2 to revision
1, the ControllerRevision with `.revision: 1` will become `.revision: 3`.
-->
{{< note >}}
注意 DaemonSet 修订版本只会正向变化。也就是说,回滚完成后,所回滚到的
`ControllerRevision` 版本号 (`.revision` 字段) 会增加。
例如,如果用户在系统中有版本 1 和版本 2并从版本 2 回滚到版本 1
带有 `.revision: 1` 的`ControllerRevision` 将变为 `.revision: 3`
{{< /note >}}
<!--
## Troubleshooting
* See [troubleshooting DaemonSet rolling
update](/docs/tasks/manage-daemon/update-daemon-set/#troubleshooting).
-->
## 故障排查
* 参阅 [DaemonSet 滚动升级故障排除](/zh/docs/tasks/manage-daemon/update-daemon-set/#troubleshooting)。