@@ -8,6 +8,7 @@ title: Managing Kubernetes Objects Using Imperative Commands
88content_type: task
99weight: 30
1010-->
11+
1112<!-- overview -->
1213
1314<!--
@@ -16,7 +17,7 @@ imperative commands built into the `kubectl` command-line tool. This document
1617explains how those commands are organized and how to use them to manage live objects.
1718-->
1819使用构建在 ` kubectl ` 命令行工具中的指令式命令可以直接快速创建、更新和删除
19- Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理现时对象 。
20+ Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理活跃对象 。
2021
2122## {{% heading "prerequisites" %}}
2223
@@ -70,7 +71,7 @@ the Kubernetes object types.
7071
7172- ` run ` :创建一个新的 Pod 来运行一个容器。
7273- ` expose ` :创建一个新的 Service 对象为若干 Pod 提供流量负载均衡。
73- - ` autoscale ` :创建一个新的 Autoscaler 对象来自动对某控制器(如 Deployment)
74+ - ` autoscale ` :创建一个新的 Autoscaler 对象来自动对某控制器(例如: Deployment)
7475 执行水平扩缩。
7576
7677<!--
@@ -82,8 +83,8 @@ to create.
8283- `create <objecttype> [<subtype>] <instancename>`
8384-->
8485` kubectl ` 命令也支持一些对象类型驱动的创建命令。
85- 这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显,不过要求
86- 用户了解它们所要创建的对象的类别 。
86+ 这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显,
87+ 不过要求用户了解它们所要创建的对象的类别 。
8788
8889- ` create <对象类别> [<子类别>] <实例名称> `
8990
@@ -153,10 +154,10 @@ Setting this aspect may set different fields for different object types:
153154
154155- ` set <字段> ` :设置对象的某一方面。
155156
157+ {{< note >}}
156158<!--
157159In Kubernetes version 1.5, not every verb-driven command has an associated aspect-driven command.
158160-->
159- {{< note >}}
160161在 Kubernetes 1.5 版本中,并非所有动词驱动的命令都有对应的方面驱动的命令。
161162{{< /note >}}
162163
@@ -169,11 +170,11 @@ however they require a better understanding of the Kubernetes object schema.
169170For more details on patch strings, see the patch section in
170171[API Conventions](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#patch-operations).
171172-->
172- ` kubectl ` 工具支持以下额外的方式用来直接更新现时对象 ,不过这些操作要求
173+ ` kubectl ` 工具支持以下额外的方式用来直接更新活跃对象 ,不过这些操作要求
173174用户对 Kubernetes 对象的模式定义有很好的了解:
174175
175- - ` edit ` :通过在编辑器中打开现时对象的配置 ,直接编辑其原始配置。
176- - ` patch ` :通过使用补丁字符串(Patch String)直接更改某现时对象的的特定字段 。
176+ - ` edit ` :通过在编辑器中打开活跃对象的配置 ,直接编辑其原始配置。
177+ - ` patch ` :通过使用补丁字符串(Patch String)直接更改某活跃对象的特定字段 。
177178 关于补丁字符串的更详细信息,参见
178179 [ API 约定] ( https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#patch-operations )
179180 的 patch 节。
@@ -191,34 +192,48 @@ You can use the `delete` command to delete an object from a cluster:
191192
192193- ` delete <类别>/<名称> `
193194
195+ {{< note >}}
194196<!--
195197You can use `kubectl delete` for both imperative commands and imperative object
196198configuration. The difference is in the arguments passed to the command. To use
197199`kubectl delete` as an imperative command, pass the object to be deleted as
198200an argument. Here's an example that passes a Deployment object named nginx:
199201-->
200- 你可以使用 ` kubectl delete ` 来执行指令式命令或者指令式对象配置。不同之处在于
201- 传递给命令的参数。要将 ` kubectl delete ` 作为指令式命令使用,将要删除的对象作为
202- 参数传递给它。下面是一个删除名为 ` nginx ` 的 Deployment 对象的命令:
202+ 你可以使用 ` kubectl delete ` 来执行指令式命令或者指令式对象配置。不同之处在于传递给命令的参数。
203+ 要将 ` kubectl delete ` 作为指令式命令使用,将要删除的对象作为参数传递给它。
204+ 下面是一个删除名为 ` nginx ` 的 Deployment 对象的命令:
205+ {{< /note >}}
203206
204207``` shell
205208kubectl delete deployment/nginx
206209```
207210
208211<!--
209212## How to view an object
213+ -->
214+ ## 如何查看对象 {#how-to-view-an-object}
210215
211216{{< comment >}}
217+ <!-- -
212218TODO(pwittrock): Uncomment this when implemented.
213219
214220You can use `kubectl view` to print specific fields of an object.
215221
216222- `view`: Prints the value of a specific field of an object.
223+ -->
224+ 你可以使用 ` kubectl view ` 打印对象的特定字段。
225+
226+ - ` view ` :打印对象的特定字段的值。
217227
218228{{< /comment >}}
219- -->
220- ## 如何查看对象 {#how-to-view-an-object}
221229
230+ <!--
231+ There are several commands for printing information about an object:
232+
233+ - `get`: Prints basic information about matching objects. Use `get -h` to see a list of options.
234+ - `describe`: Prints aggregated detailed information about matching objects.
235+ - `logs`: Prints the stdout and stderr for a container running in a Pod.
236+ -->
222237用来打印对象信息的命令有好几个:
223238
224239- ` get ` :打印匹配到的对象的基本信息。使用 ` get -h ` 可以查看选项列表。
@@ -234,12 +249,12 @@ in a `create` command. In some of those cases, you can use a combination of
234249creation. This is done by piping the output of the `create` command to the
235250`set` command, and then back to the `create` command. Here's an example:
236251-->
237- ## 使用 ` set ` 命令在创建对象之前修改对象
252+ ## 使用 ` set ` 命令在创建对象之前修改对象 {#using-set-commands-to-modify-objects-before-creation}
238253
239- 有些对象字段在 ` create ` 命令中没有对应的标志。在这些场景中,
240- 你可以使用 ` set ` 和 ` create ` 命令的组合来在对象创建之前设置字段值。
241- 这是通过将 ` create ` 命令的输出用管道方式传递给 ` set ` 命令来实现的,
242- 最后执行 ` create ` 命令来创建对象。 下面是一个例子:
254+ 有些对象字段在 ` create ` 命令中没有对应的标志。
255+ 在这些场景中, 你可以使用 ` set ` 和 ` create ` 命令的组合来在对象创建之前设置字段值。
256+ 这是通过将 ` create ` 命令的输出用管道方式传递给 ` set ` 命令来实现的,最后执行 ` create ` 命令来创建对象。
257+ 下面是一个例子:
243258
244259``` sh
245260kubectl 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
2502651. The `kubectl set selector --local -f - -o yaml` command reads the configuration from stdin, and writes the updated configuration to stdout as YAML.
2512661. The `kubectl create -f -` command creates the object using the configuration provided via stdin.
252267-->
253- 1 . 命令 ` kubectl create service -o yaml --dry-run=client ` 创建 Service 的配置,但
254- 将其以 YAML 格式在标准输出上打印而不是发送给 API 服务器。
255- 1 . 命令 ` kubectl set selector --local -f - -o yaml ` 从标准输入读入配置,并将更新后的
256- 配置以 YAML 格式输出到标准输出。
268+ 1 . 命令 ` kubectl create service -o yaml --dry-run=client ` 创建 Service 的配置,
269+ 但将其以 YAML 格式在标准输出上打印而不是发送给 API 服务器。
270+ 1 . 命令 ` kubectl set selector --local -f - -o yaml ` 从标准输入读入配置,
271+ 并将更新后的配置以 YAML 格式输出到标准输出。
2572721 . 命令 ` kubectl create -f - ` 使用标准输入上获得的配置创建对象。
258273
259274<!--
@@ -262,7 +277,7 @@ kubectl create service clusterip my-svc --clusterip="None" -o yaml --dry-run=cli
262277You can use `kubectl create --edit` to make arbitrary changes to an object
263278before it is created. Here's an example:
264279-->
265- ## 在创建之前使用 ` --edit ` 更改对象
280+ ## 在创建之前使用 ` --edit ` 更改对象 {#using-edit-to-modify-objects-before-creation}
266281
267282你可以用 ` kubectl create --edit ` 来在对象被创建之前执行任意的变更。
268283下面是一个例子:
@@ -276,8 +291,7 @@ kubectl create --edit -f /tmp/srv.yaml
2762911. The `kubectl create service` command creates the configuration for the Service and saves it to `/tmp/srv.yaml`.
2772921. The `kubectl create --edit` command opens the configuration file for editing before it creates the object.
278293-->
279- 1 . 命令 ` kubectl create service ` 创建 Service 的配置并将其保存到
280- ` /tmp/srv.yaml ` 文件。
294+ 1 . 命令 ` kubectl create service ` 创建 Service 的配置并将其保存到 ` /tmp/srv.yaml ` 文件。
2812951 . 命令 ` kubectl create --edit ` 在创建 Service 对象打开其配置文件进行编辑。
282296
283297## {{% heading "whatsnext" %}}
@@ -292,4 +306,3 @@ kubectl create --edit -f /tmp/srv.yaml
292306* [ 使用配置文件对 Kubernetes 对象进行声明式管理] ( /zh-cn/docs/tasks/manage-kubernetes-objects/declarative-config/ )
293307* [ Kubectl 命令参考] ( /docs/reference/generated/kubectl/kubectl-commands/ )
294308* [ Kubernetes API 参考] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)
295-
0 commit comments