@@ -8,6 +8,7 @@ title: Managing Kubernetes Objects Using Imperative Commands
|
8 | 8 | content_type: task
|
9 | 9 | weight: 30
|
10 | 10 | -->
|
| 11 | + |
11 | 12 | <!-- overview -->
|
12 | 13 |
|
13 | 14 | <!--
|
@@ -16,7 +17,7 @@ imperative commands built into the `kubectl` command-line tool. This document
|
16 | 17 | explains how those commands are organized and how to use them to manage live objects.
|
17 | 18 | -->
|
18 | 19 | 使用构建在 `kubectl` 命令行工具中的指令式命令可以直接快速创建、更新和删除
|
19 |
| -Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理现时对象。 |
| 20 | +Kubernetes 对象。本文档解释这些命令的组织方式以及如何使用它们来管理活跃对象。 |
20 | 21 |
|
21 | 22 | ## {{% heading "prerequisites" %}}
|
22 | 23 |
|
@@ -70,7 +71,7 @@ the Kubernetes object types.
|
70 | 71 |
|
71 | 72 | - `run`:创建一个新的 Pod 来运行一个容器。
|
72 | 73 | - `expose`:创建一个新的 Service 对象为若干 Pod 提供流量负载均衡。
|
73 |
| -- `autoscale`:创建一个新的 Autoscaler 对象来自动对某控制器(如 Deployment) |
| 74 | +- `autoscale`:创建一个新的 Autoscaler 对象来自动对某控制器(例如:Deployment) |
74 | 75 | 执行水平扩缩。
|
75 | 76 |
|
76 | 77 | <!--
|
@@ -82,8 +83,8 @@ to create.
|
82 | 83 | - `create <objecttype> [<subtype>] <instancename>`
|
83 | 84 | -->
|
84 | 85 | `kubectl` 命令也支持一些对象类型驱动的创建命令。
|
85 |
| -这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显,不过要求 |
86 |
| -用户了解它们所要创建的对象的类别。 |
| 86 | +这些命令可以支持更多的对象类别,并且在其动机上体现得更为明显, |
| 87 | +不过要求用户了解它们所要创建的对象的类别。 |
87 | 88 |
|
88 | 89 | - `create <对象类别> [<子类别>] <实例名称>`
|
89 | 90 |
|
@@ -153,10 +154,10 @@ Setting this aspect may set different fields for different object types:
|
153 | 154 |
|
154 | 155 | - `set <字段>`:设置对象的某一方面。
|
155 | 156 |
|
| 157 | +{{< note >}} |
156 | 158 | <!--
|
157 | 159 | In Kubernetes version 1.5, not every verb-driven command has an associated aspect-driven command.
|
158 | 160 | -->
|
159 |
| -{{< note >}} |
160 | 161 | 在 Kubernetes 1.5 版本中,并非所有动词驱动的命令都有对应的方面驱动的命令。
|
161 | 162 | {{< /note >}}
|
162 | 163 |
|
@@ -169,11 +170,11 @@ however they require a better understanding of the Kubernetes object schema.
|
169 | 170 | For more details on strings, see the section in
|
170 | 171 | [API Conventions](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#-operations).
|
171 | 172 | -->
|
172 |
| -`kubectl` 工具支持以下额外的方式用来直接更新现时对象,不过这些操作要求 |
| 173 | +`kubectl` 工具支持以下额外的方式用来直接更新活跃对象,不过这些操作要求 |
173 | 174 | 用户对 Kubernetes 对象的模式定义有很好的了解:
|
174 | 175 |
|
175 |
| -- `edit`:通过在编辑器中打开现时对象的配置,直接编辑其原始配置。 |
176 |
| -- ``:通过使用补丁字符串( String)直接更改某现时对象的的特定字段。 |
| 176 | +- `edit`:通过在编辑器中打开活跃对象的配置,直接编辑其原始配置。 |
| 177 | +- ``:通过使用补丁字符串( String)直接更改某活跃对象的特定字段。 |
177 | 178 | 关于补丁字符串的更详细信息,参见
|
178 | 179 | [API 约定](https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#-operations)
|
179 | 180 | 的 节。
|
@@ -191,34 +192,48 @@ You can use the `delete` command to delete an object from a cluster:
|
191 | 192 |
|
192 | 193 | - `delete <类别>/<名称>`
|
193 | 194 |
|
| 195 | +{{< note >}} |
194 | 196 | <!--
|
195 | 197 | You can use `kubectl delete` for both imperative commands and imperative object
|
196 | 198 | configuration. The difference is in the arguments passed to the command. To use
|
197 | 199 | `kubectl delete` as an imperative command, pass the object to be deleted as
|
198 | 200 | an argument. Here's an example that passes a Deployment object named nginx:
|
199 | 201 | -->
|
200 |
| -你可以使用 `kubectl delete` 来执行指令式命令或者指令式对象配置。不同之处在于 |
201 |
| -传递给命令的参数。要将 `kubectl delete` 作为指令式命令使用,将要删除的对象作为 |
202 |
| -参数传递给它。下面是一个删除名为 `nginx` 的 Deployment 对象的命令: |
| 202 | +你可以使用 `kubectl delete` 来执行指令式命令或者指令式对象配置。不同之处在于传递给命令的参数。 |
| 203 | +要将 `kubectl delete` 作为指令式命令使用,将要删除的对象作为参数传递给它。 |
| 204 | +下面是一个删除名为 `nginx` 的 Deployment 对象的命令: |
| 205 | +{{< /note >}} |
203 | 206 |
|
204 | 207 | ```shell
|
205 | 208 | kubectl delete deployment/nginx
|
206 | 209 | ```
|
207 | 210 |
|
208 | 211 | <!--
|
209 | 212 | ## How to view an object
|
| 213 | +--> |
| 214 | +## 如何查看对象 {#how-to-view-an-object} |
210 | 215 |
|
211 | 216 | {{< comment >}}
|
| 217 | +<!--- |
212 | 218 | TODO(pwittrock): Uncomment this when implemented.
|
213 | 219 |
|
214 | 220 | You can use `kubectl view` to print specific fields of an object.
|
215 | 221 |
|
216 | 222 | - `view`: Prints the value of a specific field of an object.
|
| 223 | +--> |
| 224 | +你可以使用 `kubectl view` 打印对象的特定字段。 |
| 225 | + |
| 226 | +- `view`:打印对象的特定字段的值。 |
217 | 227 |
|
218 | 228 | {{< /comment >}}
|
219 |
| ---> |
220 |
| -## 如何查看对象 {#how-to-view-an-object} |
221 | 229 |
|
| 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 | +--> |
222 | 237 | 用来打印对象信息的命令有好几个:
|
223 | 238 |
|
224 | 239 | - `get`:打印匹配到的对象的基本信息。使用 `get -h` 可以查看选项列表。
|
@@ -234,12 +249,12 @@ in a `create` command. In some of those cases, you can use a combination of
|
234 | 249 | creation. This is done by piping the output of the `create` command to the
|
235 | 250 | `set` command, and then back to the `create` command. Here's an example:
|
236 | 251 | -->
|
237 |
| -## 使用 `set` 命令在创建对象之前修改对象 |
| 252 | +## 使用 `set` 命令在创建对象之前修改对象 {#using-set-commands-to-modify-objects-before-creation} |
238 | 253 |
|
239 |
| -有些对象字段在 `create` 命令中没有对应的标志。在这些场景中, |
240 |
| -你可以使用 `set` 和 `create` 命令的组合来在对象创建之前设置字段值。 |
241 |
| -这是通过将 `create` 命令的输出用管道方式传递给 `set` 命令来实现的, |
242 |
| -最后执行 `create` 命令来创建对象。下面是一个例子: |
| 254 | +有些对象字段在 `create` 命令中没有对应的标志。 |
| 255 | +在这些场景中,你可以使用 `set` 和 `create` 命令的组合来在对象创建之前设置字段值。 |
| 256 | +这是通过将 `create` 命令的输出用管道方式传递给 `set` 命令来实现的,最后执行 `create` 命令来创建对象。 |
| 257 | +下面是一个例子: |
243 | 258 |
|
244 | 259 | ```sh
|
245 | 260 | 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
|
250 | 265 | 1. The `kubectl set selector --local -f - -o yaml` command reads the configuration from stdin, and writes the updated configuration to stdout as YAML.
|
251 | 266 | 1. The `kubectl create -f -` command creates the object using the configuration provided via stdin.
|
252 | 267 | -->
|
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 格式输出到标准输出。 |
257 | 272 | 1. 命令 `kubectl create -f -` 使用标准输入上获得的配置创建对象。
|
258 | 273 |
|
259 | 274 | <!--
|
@@ -262,7 +277,7 @@ kubectl create service clusterip my-svc --clusterip="None" -o yaml --dry-run=cli
|
262 | 277 | You can use `kubectl create --edit` to make arbitrary changes to an object
|
263 | 278 | before it is created. Here's an example:
|
264 | 279 | -->
|
265 |
| -## 在创建之前使用 `--edit` 更改对象 |
| 280 | +## 在创建之前使用 `--edit` 更改对象 {#using-edit-to-modify-objects-before-creation} |
266 | 281 |
|
267 | 282 | 你可以用 `kubectl create --edit` 来在对象被创建之前执行任意的变更。
|
268 | 283 | 下面是一个例子:
|
@@ -276,8 +291,7 @@ kubectl create --edit -f /tmp/srv.yaml
|
276 | 291 | 1. The `kubectl create service` command creates the configuration for the Service and saves it to `/tmp/srv.yaml`.
|
277 | 292 | 1. The `kubectl create --edit` command opens the configuration file for editing before it creates the object.
|
278 | 293 | -->
|
279 |
| -1. 命令 `kubectl create service` 创建 Service 的配置并将其保存到 |
280 |
| -`/tmp/srv.yaml` 文件。 |
| 294 | +1. 命令 `kubectl create service` 创建 Service 的配置并将其保存到 `/tmp/srv.yaml` 文件。 |
281 | 295 | 1. 命令 `kubectl create --edit` 在创建 Service 对象打开其配置文件进行编辑。
|
282 | 296 |
|
283 | 297 | ## {{% heading "whatsnext" %}}
|
@@ -292,4 +306,3 @@ kubectl create --edit -f /tmp/srv.yaml
|
292 | 306 | * [使用配置文件对 Kubernetes 对象进行声明式管理](/zh-cn/docs/tasks/manage-kubernetes-objects/declarative-config/)
|
293 | 307 | * [Kubectl 命令参考](/docs/reference/generated/kubectl/kubectl-commands/)
|
294 | 308 | * [Kubernetes API 参考](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/)
|
295 |
| - |
|
0 commit comments