Skip to content

Commit 7973c72

Browse files
committed
Update kubectl-plugins.md
1 parent 8b98203 commit 7973c72

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

content/zh-cn/docs/tasks/extend-kubectl/kubectl-plugins.md

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ Krew [插件索引](https://krew.sigs.k8s.io/plugins/) 所维护的 kubectl 插
6464
<!--
6565
### Discovering plugins
6666
67-
`kubectl` provides a command `kubectl plugin list` that searches your PATH for valid plugin executables.
68-
Executing this command causes a traversal of all files in your PATH. Any files that are executable, and begin with `kubectl-` will show up *in the order in which they are present in your PATH* in this command's output.
67+
`kubectl` provides a command `kubectl plugin list` that searches your `PATH` for valid plugin executables.
68+
Executing this command causes a traversal of all files in your `PATH`. Any files that are executable, and begin with `kubectl-` will show up *in the order in which they are present in your `PATH`* in this command's output.
6969
A warning will be included for any files beginning with `kubectl-` that are *not* executable.
7070
A warning will also be included for any valid plugin files that overlap each other's name.
7171
@@ -75,8 +75,9 @@ plugins from a community-curated
7575
-->
7676
### 发现插件
7777

78-
`kubectl` 提供一个命令 `kubectl plugin list`,用于搜索路径查找有效的插件可执行文件。
79-
执行此命令将遍历路径中的所有文件。任何以 `kubectl-` 开头的可执行文件都将在这个命令的输出中以它们在路径中出现的顺序显示。
78+
`kubectl` 提供一个命令 `kubectl plugin list`,用于搜索 `PATH` 查找有效的插件可执行文件。
79+
执行此命令将遍历 `PATH` 中的所有文件。任何以 `kubectl-` 开头的可执行文件都将在这个命令的输出中**以它们在
80+
`PATH` 中出现的顺序**显示。
8081
任何以 `kubectl-` 开头的文件如果`不可执行`,都将包含一个警告。
8182
对于任何相同的有效插件文件,都将包含一个警告。
8283

@@ -161,9 +162,9 @@ sudo chmod +x ./kubectl-foo
161162
```
162163

163164
<!--
164-
and place it anywhere in your PATH:
165+
and place it anywhere in your `PATH`:
165166
-->
166-
并将它放在你的 PATH 中的任何地方:
167+
并将它放在你的 `PATH` 中的任何地方:
167168

168169
```shell
169170
sudo mv ./kubectl-foo /usr/local/bin
@@ -218,7 +219,7 @@ KUBECONFIG=/etc/kube/config kubectl foo config
218219
```
219220

220221
<!--
221-
Additionally, the first argument that is passed to a plugin will always be the full path to the location where it was invoked (`$0` would equal `/usr/local/bin/kubectl-foo` in our example above).
222+
Additionally, the first argument that is passed to a plugin will always be the full path to the location where it was invoked (`$0` would equal `/usr/local/bin/kubectl-foo` in the example above).
222223
-->
223224
此外,传递给插件的第一个参数总是调用它的位置的绝对路径(在上面的例子中,`$0` 将等于 `/usr/local/bin/kubectl-foo`)。
224225

@@ -239,12 +240,12 @@ For example, a plugin that wishes to be invoked whenever the command `kubectl fo
239240
#### 参数和标记处理
240241

241242
<!--
242-
The plugin mechanism doest _not_ create any custom, plugin-specific values or environment variables to a plugin process.
243+
The plugin mechanism does _not_ create any custom, plugin-specific values or environment variables for a plugin process.
243244
244245
An older kubectl plugin mechanism provided environment variables such as `KUBECTL_PLUGINS_CURRENT_NAMESPACE`; that no longer happens.
245246
-->
246247
{{< note >}}
247-
插件机制不会为插件进程创建任何定制的、特定于插件的值或环境变量。
248+
插件机制**不会**为插件进程创建任何定制的、特定于插件的值或环境变量。
248249

249250
较老的插件机制会提供环境变量(例如 `KUBECTL_PLUGINS_CURRENT_NAMESPACE`);这种机制已被废弃。
250251
{{< /note >}}
@@ -259,14 +260,11 @@ kubectl 插件必须解析并检查传递给它们的所有参数。
259260
参阅[使用命令行运行时包](#using-the-command-line-runtime-package)了解针对
260261
插件开发人员的 Go 库的细节。
261262

262-
<!--
263-
Here are some additional cases where users invoke your plugin while providing additional flags and arguments. This builds upon the `kubectl-foo-bar-baz` plugin from the scenario above.
264-
-->
265263
这里是一些用户调用你的插件的时候提供额外标志和参数的场景。
266264
这些场景时基于上述案例中的 `kubectl-foo-bar-baz` 插件的。
267265

268266
<!--
269-
If you run `kubectl foo bar baz arg1 -flag=value arg2`, kubectl's plugin mechanism will first try to find the plugin with the longest possible name, which in this case
267+
If you run `kubectl foo bar baz arg1 --flag=value arg2`, kubectl's plugin mechanism will first try to find the plugin with the longest possible name, which in this case
270268
would be `kubectl-foo-bar-baz-arg1`. Upon not finding that plugin, kubectl then treats the last dash-separated value as an argument (`arg1` in this case), and attempts to find the next longest possible name, `kubectl-foo-bar-baz`.
271269
Upon having found a plugin with this name, kubectl then invokes that plugin, passing all args and flags after the plugin's name as arguments to the plugin process.
272270
-->
@@ -309,9 +307,9 @@ My first command-line argument was arg1
309307
```
310308

311309
<!--
312-
As you can see, our plugin was found based on the `kubectl` command specified by a user, and all extra arguments and flags were passed as-is to the plugin executable once it was found.
310+
As you can see, your plugin was found based on the `kubectl` command specified by a user, and all extra arguments and flags were passed as-is to the plugin executable once it was found.
313311
-->
314-
正如你所看到的,我们的插件是基于用户指定的 `kubectl` 命令找到的,
312+
正如你所看到的,你的插件是基于用户指定的 `kubectl` 命令找到的,
315313
所有额外的参数和标记都是按原样传递给插件可执行文件的。
316314

317315
<!--
@@ -344,10 +342,10 @@ I am a plugin with a dash in my name
344342
```
345343

346344
<!--
347-
Note that the introduction of underscores to a plugin filename does not prevent us from having commands such as `kubectl foo_bar`.
345+
Note that the introduction of underscores to a plugin filename does not prevent you from having commands such as `kubectl foo_bar`.
348346
The command from the above example, can be invoked using either a dash (`-`) or an underscore (`_`):
349347
-->
350-
请注意,在插件文件名中引入下划线并不会阻止我们使用 `kubectl foo_bar` 之类的命令。
348+
请注意,在插件文件名中引入下划线并不会阻止你使用 `kubectl foo_bar` 之类的命令。
351349
可以使用破折号(`-`)或下划线(`_`)调用上面示例中的命令:
352350

353351
```shell
@@ -371,8 +369,8 @@ I am a plugin with a dash in my name
371369
<!--
372370
#### Name conflicts and overshadowing
373371
374-
It is possible to have multiple plugins with the same filename in different locations throughout your PATH.
375-
For example, given a PATH with the following value: `PATH=/usr/local/bin/plugins:/usr/local/bin/moreplugins`, a copy of plugin `kubectl-foo` could exist in `/usr/local/bin/plugins` and `/usr/local/bin/moreplugins`,
372+
It is possible to have multiple plugins with the same filename in different locations throughout your `PATH`.
373+
For example, given a `PATH` with the following value: `PATH=/usr/local/bin/plugins:/usr/local/bin/moreplugins`, a copy of plugin `kubectl-foo` could exist in `/usr/local/bin/plugins` and `/usr/local/bin/moreplugins`,
376374
such that the output of the `kubectl plugin list` command is:
377375
-->
378376
#### 命名冲突和弊端
@@ -397,54 +395,58 @@ error: one plugin warning was found
397395
```
398396

399397
<!--
400-
In the above scenario, the warning under `/usr/local/bin/moreplugins/kubectl-foo` tells us that this plugin will never be executed. Instead, the executable that appears first in our PATH, `/usr/local/bin/plugins/kubectl-foo`, will always be found and executed first by the `kubectl` plugin mechanism.
398+
In the above scenario, the warning under `/usr/local/bin/moreplugins/kubectl-foo` tells you that this plugin will never be executed. Instead, the executable that appears first in your `PATH`, `/usr/local/bin/plugins/kubectl-foo`, will always be found and executed first by the `kubectl` plugin mechanism.
401399
-->
402-
在上面的场景中 `/usr/local/bin/moreplugins/kubectl-foo` 下的警告告诉我们这个插件永远不会被执行
403-
相反,首先出现在我们路径中的可执行文件 `/usr/local/bin/plugins/kubectl-foo`
400+
在上面的场景中 `/usr/local/bin/moreplugins/kubectl-foo` 下的警告告诉你这个插件永远不会被执行
401+
相反,首先出现在你 `PATH` 中的可执行文件 `/usr/local/bin/plugins/kubectl-foo`
404402
总是首先被 `kubectl` 插件机制找到并执行。
405403

406404
<!--
407-
A way to resolve this issue is to ensure that the location of the plugin that you wish to use with `kubectl` always comes first in your PATH. For example, if we wanted to always use `/usr/local/bin/moreplugins/kubectl-foo` anytime that the `kubectl` command `kubectl foo` was invoked, we would simply change the value of our PATH to be `PATH=/usr/local/bin/moreplugins:/usr/local/bin/plugins`.
405+
A way to resolve this issue is to ensure that the location of the plugin that you wish to use with `kubectl` always comes first in your `PATH`. For example, if you want to always use `/usr/local/bin/moreplugins/kubectl-foo` anytime that the `kubectl` command `kubectl foo` was invoked, change the value of your `PATH` to be `/usr/local/bin/moreplugins:/usr/local/bin/plugins`.
408406
-->
409-
解决这个问题的一种方法是你确保你希望与 `kubectl` 一起使用的插件的位置总是在你的路径中首先出现
410-
例如,如果我们总是想使用 `/usr/local/bin/moreplugins/kubectl foo`
411-
那么在调用 `kubectl` 命令 `kubectl foo` 时,我们只需将路径的值更改为 `PATH=/usr/local/bin/moreplugins:/usr/local/bin/plugins`
407+
解决这个问题的一种方法是你确保你希望与 `kubectl` 一起使用的插件的位置总是在你的 `PATH` 中首先出现
408+
例如,如果你总是想使用 `/usr/local/bin/moreplugins/kubectl foo`
409+
那么在调用 `kubectl` 命令 `kubectl foo` 时,你只需将路径的值更改为 `/usr/local/bin/moreplugins:/usr/local/bin/plugins`
412410

413411
<!--
414412
#### Invocation of the longest executable filename
415413
416-
There is another kind of overshadowing that can occur with plugin filenames. Given two plugins present in a user's PATH `kubectl-foo-bar` and `kubectl-foo-bar-baz`, the `kubectl` plugin mechanism will always choose the longest possible plugin name for a given user command. Some examples below, clarify this further:
414+
There is another kind of overshadowing that can occur with plugin filenames. Given two plugins present in a user's `PATH`: `kubectl-foo-bar` and `kubectl-foo-bar-baz`, the `kubectl` plugin mechanism will always choose the longest possible plugin name for a given user command. Some examples below, clarify this further:
417415
-->
418416
#### 调用最长的可执行文件名
419417

420-
对于插件文件名而言还有另一种弊端,给定用户路径中的两个插件 `kubectl-foo-bar``kubectl-foo-bar-baz`
418+
对于插件文件名而言还有另一种弊端,给定用户 `PATH` 中的两个插件 `kubectl-foo-bar``kubectl-foo-bar-baz`
421419
`kubectl` 插件机制总是为给定的用户命令选择尽可能长的插件名称。下面的一些例子进一步的说明了这一点:
422420

423421
```bash
424422
# 对于给定的 kubectl 命令,最长可能文件名的插件是被优先选择的
425423
kubectl foo bar baz
426424
```
425+
427426
```
428427
Plugin kubectl-foo-bar-baz is executed
429428
```
430429

431430
```bash
432431
kubectl foo bar
433432
```
433+
434434
```
435435
Plugin kubectl-foo-bar is executed
436436
```
437437

438438
```bash
439439
kubectl foo bar baz buz
440440
```
441+
441442
```
442443
Plugin kubectl-foo-bar-baz is executed, with "buz" as its first argument
443444
```
444445

445446
```bash
446447
kubectl foo bar buz
447448
```
449+
448450
```
449451
Plugin kubectl-foo-bar is executed, with "buz" as its first argument
450452
```
@@ -477,6 +479,7 @@ You can use the aforementioned `kubectl plugin list` command to ensure that your
477479
```bash
478480
kubectl plugin list
479481
```
482+
480483
```
481484
The following kubectl-compatible plugins are available:
482485
@@ -554,7 +557,7 @@ on Linux, Chocolatey on Windows, and Homebrew on macOS. Any package
554557
manager will be suitable if it can place new executables placed somewhere
555558
in the user's `PATH`.
556559
As a plugin author, if you pick this option then you also have the burden
557-
of updating your kubectl plugins distribution package across multiple
560+
of updating your kubectl plugin's distribution package across multiple
558561
platforms for each release.
559562
-->
560563
### 原生的与特定平台的包管理 {#distributing-native}
@@ -584,10 +587,13 @@ installs easier.
584587
## {{% heading "whatsnext" %}}
585588

586589
<!--
587-
* Check the Sample CLI Plugin repository for [a detailed example](https://github.com/kubernetes/sample-cli-plugin) of a plugin written in Go.
588-
* In case of any questions, feel free to reach out to the [CLI SIG team](https://github.com/kubernetes/community/tree/master/sig-cli).
590+
* Check the Sample CLI Plugin repository for a
591+
[detailed example](https://github.com/kubernetes/sample-cli-plugin) of a
592+
plugin written in Go.
593+
In case of any questions, feel free to reach out to the
594+
[SIG CLI team](https://github.com/kubernetes/community/tree/master/sig-cli).
589595
* Read about [Krew](https://krew.dev/), a package manager for kubectl plugins.
590596
-->
591597
* 查看 CLI 插件库示例,查看用 Go 编写的插件的[详细示例](https://github.com/kubernetes/sample-cli-plugin)
592-
* 如有任何问题,请随时联系 [SIG CLI ](https://github.com/kubernetes/community/tree/master/sig-cli)
598+
* 如有任何问题,请随时联系 [SIG CLI 团队](https://github.com/kubernetes/community/tree/master/sig-cli)
593599
* 了解 [Krew](https://krew.dev/),一个 kubectl 插件管理器。

0 commit comments

Comments
 (0)