diff --git a/content/zh-cn/docs/tasks/manage-kubernetes-objects/_index.md b/content/zh-cn/docs/tasks/manage-kubernetes-objects/_index.md index 88059fb9cd..6e817952b6 100644 --- a/content/zh-cn/docs/tasks/manage-kubernetes-objects/_index.md +++ b/content/zh-cn/docs/tasks/manage-kubernetes-objects/_index.md @@ -3,3 +3,9 @@ title: "管理 Kubernetes 对象" weight: 25 description: 用声明式和命令式范型与 Kubernetes API 交互。 --- + + \ No newline at end of file diff --git a/content/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-command.md b/content/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-command.md index 2accf8233b..0f294f9c0f 100644 --- a/content/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-command.md +++ b/content/zh-cn/docs/tasks/manage-kubernetes-objects/imperative-command.md @@ -8,6 +8,7 @@ title: Managing Kubernetes Objects Using Imperative Commands content_type: task weight: 30 --> + 使用构建在 `kubectl` 命令行工具中的指令式命令可以直接快速创建、更新和删除 -Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理现时对象。 +Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理活跃对象。 ## {{% heading "prerequisites" %}} @@ -70,7 +71,7 @@ the Kubernetes object types. - `run`:创建一个新的 Pod 来运行一个容器。 - `expose`:创建一个新的 Service 对象为若干 Pod 提供流量负载均衡。 -- `autoscale`:创建一个新的 Autoscaler 对象来自动对某控制器(如 Deployment) +- `autoscale`:创建一个新的 Autoscaler 对象来自动对某控制器(例如:Deployment) 执行水平扩缩。 `kubectl` 命令也支持一些对象类型驱动的创建命令。 -这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显,不过要求 -用户了解它们所要创建的对象的类别。 +这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显, +不过要求用户了解它们所要创建的对象的类别。 - `create <对象类别> [<子类别>] <实例名称>` @@ -153,10 +154,10 @@ Setting this aspect may set different fields for different object types: - `set <字段>`:设置对象的某一方面。 +{{< note >}} -{{< note >}} 在 Kubernetes 1.5 版本中,并非所有动词驱动的命令都有对应的方面驱动的命令。 {{< /note >}} @@ -169,11 +170,11 @@ however they require a better understanding of the Kubernetes object schema. For more details on patch strings, see the patch section in [API Conventions](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#patch-operations). --> -`kubectl` 工具支持以下额外的方式用来直接更新现时对象,不过这些操作要求 +`kubectl` 工具支持以下额外的方式用来直接更新活跃对象,不过这些操作要求 用户对 Kubernetes 对象的模式定义有很好的了解: -- `edit`:通过在编辑器中打开现时对象的配置,直接编辑其原始配置。 -- `patch`:通过使用补丁字符串(Patch String)直接更改某现时对象的的特定字段。 +- `edit`:通过在编辑器中打开活跃对象的配置,直接编辑其原始配置。 +- `patch`:通过使用补丁字符串(Patch String)直接更改某活跃对象的特定字段。 关于补丁字符串的更详细信息,参见 [API 约定](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#patch-operations) 的 patch 节。 @@ -191,15 +192,17 @@ You can use the `delete` command to delete an object from a cluster: - `delete <类别>/<名称>` +{{< note >}} -你可以使用 `kubectl delete` 来执行指令式命令或者指令式对象配置。不同之处在于 -传递给命令的参数。要将 `kubectl delete` 作为指令式命令使用,将要删除的对象作为 -参数传递给它。下面是一个删除名为 `nginx` 的 Deployment 对象的命令: +你可以使用 `kubectl delete` 来执行指令式命令或者指令式对象配置。不同之处在于传递给命令的参数。 +要将 `kubectl delete` 作为指令式命令使用,将要删除的对象作为参数传递给它。 +下面是一个删除名为 `nginx` 的 Deployment 对象的命令: +{{< /note >}} ```shell kubectl delete deployment/nginx @@ -207,18 +210,30 @@ kubectl delete deployment/nginx +## 如何查看对象 {#how-to-view-an-object} {{< comment >}} + +你可以使用 `kubectl view` 打印对象的特定字段。 + +- `view`:打印对象的特定字段的值。 {{< /comment >}} ---> -## 如何查看对象 {#how-to-view-an-object} + 用来打印对象信息的命令有好几个: - `get`:打印匹配到的对象的基本信息。使用 `get -h` 可以查看选项列表。 @@ -234,12 +249,12 @@ in a `create` command. In some of those cases, you can use a combination of creation. This is done by piping the output of the `create` command to the `set` command, and then back to the `create` command. Here's an example: --> -## 使用 `set` 命令在创建对象之前修改对象 +## 使用 `set` 命令在创建对象之前修改对象 {#using-set-commands-to-modify-objects-before-creation} -有些对象字段在 `create` 命令中没有对应的标志。在这些场景中, -你可以使用 `set` 和 `create` 命令的组合来在对象创建之前设置字段值。 -这是通过将 `create` 命令的输出用管道方式传递给 `set` 命令来实现的, -最后执行 `create` 命令来创建对象。下面是一个例子: +有些对象字段在 `create` 命令中没有对应的标志。 +在这些场景中,你可以使用 `set` 和 `create` 命令的组合来在对象创建之前设置字段值。 +这是通过将 `create` 命令的输出用管道方式传递给 `set` 命令来实现的,最后执行 `create` 命令来创建对象。 +下面是一个例子: ```sh kubectl create service clusterip my-svc --clusterip="None" -o yaml --dry-run=client | kubectl set selector --local -f - 'environment=qa' -o yaml | kubectl create -f - @@ -250,10 +265,10 @@ kubectl create service clusterip my-svc --clusterip="None" -o yaml --dry-run=cli 1. The `kubectl set selector --local -f - -o yaml` command reads the configuration from stdin, and writes the updated configuration to stdout as YAML. 1. The `kubectl create -f -` command creates the object using the configuration provided via stdin. --> -1. 命令 `kubectl create service -o yaml --dry-run=client` 创建 Service 的配置,但 - 将其以 YAML 格式在标准输出上打印而不是发送给 API 服务器。 -1. 命令 `kubectl set selector --local -f - -o yaml` 从标准输入读入配置,并将更新后的 - 配置以 YAML 格式输出到标准输出。 +1. 命令 `kubectl create service -o yaml --dry-run=client` 创建 Service 的配置, + 但将其以 YAML 格式在标准输出上打印而不是发送给 API 服务器。 +1. 命令 `kubectl set selector --local -f - -o yaml` 从标准输入读入配置, + 并将更新后的配置以 YAML 格式输出到标准输出。 1. 命令 `kubectl create -f -` 使用标准输入上获得的配置创建对象。 -## 在创建之前使用 `--edit` 更改对象 +## 在创建之前使用 `--edit` 更改对象 {#using-edit-to-modify-objects-before-creation} 你可以用 `kubectl create --edit` 来在对象被创建之前执行任意的变更。 下面是一个例子: @@ -276,8 +291,7 @@ kubectl create --edit -f /tmp/srv.yaml 1. The `kubectl create service` command creates the configuration for the Service and saves it to `/tmp/srv.yaml`. 1. The `kubectl create --edit` command opens the configuration file for editing before it creates the object. --> -1. 命令 `kubectl create service` 创建 Service 的配置并将其保存到 - `/tmp/srv.yaml` 文件。 +1. 命令 `kubectl create service` 创建 Service 的配置并将其保存到 `/tmp/srv.yaml` 文件。 1. 命令 `kubectl create --edit` 在创建 Service 对象打开其配置文件进行编辑。 ## {{% heading "whatsnext" %}} @@ -292,4 +306,3 @@ kubectl create --edit -f /tmp/srv.yaml * [使用配置文件对 Kubernetes 对象进行声明式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/declarative-config/) * [Kubectl 命令参考](/docs/reference/generated/kubectl/kubectl-commands/) * [Kubernetes API 参考](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/) -