update zh-trans content/zh/docs/reference/kubectl/conventions.md (#18347)

This commit is contained in:
chentanjun 2019-12-30 11:49:39 +08:00 committed by Kubernetes Prow Robot
parent ea9a1d78ac
commit 3022f7c81a
1 changed files with 57 additions and 67 deletions

View File

@ -60,16 +60,16 @@ For `kubectl run` to satisfy infrastructure as code:
<!--
* Tag the image with a version-specific tag and don't move that tag to a new version. For example, use `:v1234`, `v1.2.3`, `r03062016-1-4`, rather than `:latest` (For more information, see [Best Practices for Configuration](/docs/concepts/configuration/overview/#container-images)).
* Capture the parameters in a checked-in script, or at least use `--record` to annotate the created objects with the command line for an image that is lightly parameterized.
* Pin to a specific [generator](#generators) version, such as `kubectl run --generator=run-pod/v1`.
* Check in the script for an image that is heavily parameterized.
* Switch to configuration files checked into source control for features that are needed, but not expressible via `kubectl run` flags.
* Pin to a specific [generator](#generators) version, such as `kubectl run --generator=deployment/v1beta1`.
-->
* 使用特定版本的标签标记镜像,不要将该标签移动到新版本。例如,使用 `:v1234`、`v1.2.3`、`r03062016-1-4`,而不是 `:latest`(有关详细信息,请参阅[配置的最佳实践](/docs/concepts/configuration/overview/#container-images))。
* 固定到特定的[生成器](#生成器)版本,例如 `kubectl run --generator=run-pod/v1`
* 使用基于版本控制的脚本来记录所使用的参数,或者至少使用 `--record` 参数以便为所创建的对象添加注解,在使用轻度参数化的镜像时,记录下所使用的命令行。
* 使用基于版本控制的脚本来运行包含大量参数的镜像。
* 对于无法通过 `kubectl run` 参数来表示的功能特性,使用基于源码控制的配置文件,以记录要使用的功能特性。
* 固定到特定的[生成器](#生成器)版本,例如 `kubectl run --generator=deployment/v1beta1`
<!--
#### Generators
@ -82,82 +82,72 @@ You can create the following resources using `kubectl run` with the `--generator
您可以使用带有 `--generator` 参数的 `kubectl run` 命令创建如下资源:
<!--
| Resource | api group | kubectl command |
|-------------------------------------|--------------------|---------------------------------------------------|
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| Replication controller (deprecated) | v1 | `kubectl run --generator=run/v1` |
| Deployment (deprecated) | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment (deprecated) | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job (deprecated) | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob (deprecated) | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
| CronJob (deprecated) | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
{{< table caption="Resources you can create using kubectl run" >}}
| Resource | API group | kubectl command |
|--------------------------------------|--------------------|---------------------------------------------------|
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| ReplicationController _(deprecated)_ | v1 | `kubectl run --generator=run/v1` |
| Deployment _(deprecated)_ | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment _(deprecated)_ | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job _(deprecated)_ | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob _(deprecated)_ | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
| CronJob _(deprecated)_ | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
{{< /table >}}
-->
| 资源 | api 组 | kubectl 命令 |
|-------------------------------------|--------------------|---------------------------------------------------|
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| Replication controller (过期)) | v1 | `kubectl run --generator=run/v1` |
| Deployment (过期) | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment (过期) | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job (过期) | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob (过期) | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
| CronJob (过期) | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
<!-- {{< note >}}
`kubectl run --generator` except for `run-pod/v1` is deprecated in v1.12.
{{< /note >}} -->
{{< note >}}
v1.12 中不建议使用 `run-pod/v1` 以外的 `kubectl run --generator`
{{< /note >}}
<!--
If you do not specify a generator flag, other flags prompt you to use a specific generator. The following table lists the flags that force you to use specific generators, depending on the version of the cluster:
-->
如果不指定 generator 参数,其他参数将提示您使用特定的生成器。下表列出了强制您使用特定生成器的参数,具体取决于集群的版本:
<!--
| Generated Resource | Cluster v1.4 and later | Cluster v1.3 | Cluster v1.2 | Cluster v1.1 and earlier |
|:----------------------:|------------------------|-----------------------|--------------------------------------------|--------------------------------------------|
| Pod | `--restart=Never` | `--restart=Never` | `--generator=run-pod/v1` | `--restart=OnFailure` OR `--restart=Never` |
| Replication Controller | `--generator=run/v1` | `--generator=run/v1` | `--generator=run/v1` | `--restart=Always` |
| Deployment | `--restart=Always` | `--restart=Always` | `--restart=Always` | N/A |
| Job | `--restart=OnFailure` | `--restart=OnFailure` | `--restart=OnFailure` OR `--restart=Never` | N/A |
| Cron Job | `--schedule=<cron>` | N/A | N/A | N/A |
-->
| 生成的资源 | 集群版本 v1.4 及以后版本 | 集群版本 v1.3 | 集群版本 v1.2 | 集群版本 v1.1 及更早 |
|:----------------------:|------------------------|-----------------------|--------------------------------------------|--------------------------------------------|
| Pod | `--restart=Never` | `--restart=Never` | `--generator=run-pod/v1` | `--restart=OnFailure``--restart=Never` |
| Replication Controller | `--generator=run/v1` | `--generator=run/v1` | `--generator=run/v1` | `--restart=Always` |
| Deployment | `--restart=Always` | `--restart=Always` | `--restart=Always` | N/A |
| Job | `--restart=OnFailure` | `--restart=OnFailure` | `--restart=OnFailure``--restart=Never` | N/A |
| Cron Job | `--schedule=<cron>` | N/A | N/A | N/A |
{{< table caption="可以使用 kubectl run 创建的资源" >}}
| 资源 | API 组 | kubectl 命令 |
|----------------------------------|--------------------|-------------------------------------------------- |
| Pod | v1 | `kubectl run --generator=run-pod/v1` |
| ReplicationController _(已弃用)_ | v1 | `kubectl run --generator=run/v1` |
| Deployment _(已弃用)_ | extensions/v1beta1 | `kubectl run --generator=deployment/v1beta1` |
| Deployment _(已弃用)_ | apps/v1beta1 | `kubectl run --generator=deployment/apps.v1beta1` |
| Job _(已弃用)_ | batch/v1 | `kubectl run --generator=job/v1` |
| CronJob _(已弃用)_ | batch/v2alpha1 | `kubectl run --generator=cronjob/v2alpha1` |
| CronJob _(已弃用)_ | batch/v1beta1 | `kubectl run --generator=cronjob/v1beta1` |
{{< /table >}}
{{< note >}}
<!--
These flags use a default generator only when you have not specified any flag.
This means that when you combine `--generator` with other flags the generator that you specified later does not change. For example, in a cluster v1.4, if you initially specify
`--restart=Always`, a Deployment is created; if you later specify `--restart=Always`
and `--generator=run/v1`, a Replication Controller is created.
This enables you to pin to a specific behavior with the generator,
even when the default generator is changed later.
-->
只有在未指定任何参数时,这些参数才使用默认生成器。
这意味着,当您将 `--generator` 与其他参数组合时,随后指定的生成器不会更改。
例如,在集群版本 v1.4 中,如果最初指定了 `--restart=always`,则会创建 Deployment如果后来指定了 `--restart=always``--generator=run/v1`,则会创建 Replication Controller。
这使您能够将生成器固定到特定的行为,即使在以后更改默认生成器时也是如此。
Generators other than `run-pod/v1` are deprecated.
-->不推荐使用 `run-pod/v1` 以外的其他生成器。
{{< /note >}}
<!--
The flags set the generator in the following order: first the `--schedule` flag, then the `--restart` policy flag, and finally the `--generator` flag.
If you explicitly set `--generator`, kubectl uses the generator you specified. If you invoke `kubectl run` and don't specify a generator, kubectl automatically selects which generator to use based on the other flags you set. The following table lists flags and the generators that are activated if you didn't specify one yourself:
-->
这些参数按以下顺序设置生成器:首先是 `--schedule` 参数,然后是 `--restart` 策略参数,最后是 `--generator` 参数。
如果您显式设置了 `--generator` 参数kubectl 将使用您指定的生成器。如果使用 `kubectl run` 命令但是未指定生成器kubectl 会根据您设置的其他参数自动选择要使用的生成器。下表列出了如果您自己未指定参数自动使用与之相匹配的生成器:
<!--
To check the final resource that was created, use the `--dry-run`
flag, which provides the object to be submitted to the cluster.
{{< table caption="kubectl run flags and the resource they imply" >}}
| Flag | Generated Resource |
|-------------------------|-----------------------|
| `--schedule=<schedule>` | CronJob |
| `--restart=Always` | Deployment |
| `--restart=OnFailure` | Job |
| `--restart=Never` | Pod |
{{< /table >}}
-->
要检查最终所创建的资源,请使用 `--dry run` 参数;该参数可以提供将要提交到集群的对象。
{{< table caption="kubectl run 参数及其对应的资源" >}}
| 参数 | 相匹配的资源 |
|-------------------------|-----------------------|
| `--schedule=<schedule>` | CronJob |
| `--restart=Always` | Deployment |
| `--restart=OnFailure` | Job |
| `--restart=Never` | Pod |
{{< /table >}}
<!--
If you don't specify a generator, kubectl pays attention to other flags in the following order:
-->
如果不指定生成器kubectl 将按以下顺序考虑其他参数:
1. `--schedule`
1. `--restart`
<!--
You can use the `--dry-run` flag to preview the object that would be sent to your cluster, without really submitting it.
-->
您可以使用 `--dry-run` 参数预览要发送到集群的对象,而无需真正提交。
### `kubectl apply`