Skip to content

Commit ab12516

Browse files
authored
[zh] sync optional-kubectl-configs-bash-linux.md and mac.md (#40314)
1 parent 20d326f commit ab12516

File tree

4 files changed

+82
-32
lines changed

4 files changed

+82
-32
lines changed

content/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-bash-linux.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ _build:
66
list: never
77
render: never
88
publishResources: false
9-
109
---
1110
<!--
1211
title: "bash auto-completion on Linux"
1312
description: "Some optional configuration for bash auto-completion on Linux."
1413
headless: true
14+
_build:
15+
list: never
16+
render: never
17+
publishResources: false
1518
-->
1619

1720
<!--
@@ -20,9 +23,13 @@ headless: true
2023
### 简介 {#introduction}
2124

2225
<!--
23-
The kubectl completion script for Bash can be generated with the command `kubectl completion bash`. Sourcing the completion script in your shell enables kubectl autocompletion.
26+
The kubectl completion script for Bash can be generated with the command `kubectl completion bash`.
27+
Sourcing the completion script in your shell enables kubectl autocompletion.
2428
25-
However, the completion script depends on [**bash-completion**](https://github.com/scop/bash-completion), which means that you have to install this software first (you can test if you have bash-completion already installed by running `type _init_completion`).
29+
However, the completion script depends on
30+
[**bash-completion**](https://github.com/scop/bash-completion),
31+
which means that you have to install this software first
32+
(you can test if you have bash-completion already installed by running `type _init_completion`).
2633
-->
2734
kubectl 的 Bash 补全脚本可以用命令 `kubectl completion bash` 生成。
2835
在 Shell 中导入(Sourcing)补全脚本,将启用 kubectl 自动补全功能。
@@ -36,11 +43,16 @@ kubectl 的 Bash 补全脚本可以用命令 `kubectl completion bash` 生成。
3643
### 安装 bash-completion {#install-bash-comletion}
3744

3845
<!--
39-
bash-completion is provided by many package managers (see [here](https://github.com/scop/bash-completion#installation)). You can install it with `apt-get install bash-completion` or `yum install bash-completion`, etc.
46+
bash-completion is provided by many package managers
47+
(see [here](https://github.com/scop/bash-completion#installation)).
48+
You can install it with `apt-get install bash-completion` or `yum install bash-completion`, etc.
4049
41-
The above commands create `/usr/share/bash-completion/bash_completion`, which is the main script of bash-completion. Depending on your package manager, you have to manually source this file in your `~/.bashrc` file.
50+
The above commands create `/usr/share/bash-completion/bash_completion`,
51+
which is the main script of bash-completion. Depending on your package manager,
52+
you have to manually source this file in your `~/.bashrc` file.
4253
43-
To find out, reload your shell and run `type _init_completion`. If the command succeeds, you're already set, otherwise add the following to your `~/.bashrc` file:
54+
To find out, reload your shell and run `type _init_completion`.
55+
If the command succeeds, you're already set, otherwise add the following to your `~/.bashrc` file:
4456
-->
4557
很多包管理工具均支持 bash-completion(参见[这里](https://github.com/scop/bash-completion#installation))。
4658
可以通过 `apt-get install bash-completion``yum install bash-completion` 等命令来安装它。
@@ -68,7 +80,8 @@ Reload your shell and verify that bash-completion is correctly installed by typi
6880
#### Bash
6981

7082
<!--
71-
You now need to ensure that the kubectl completion script gets sourced in all your shell sessions. There are two ways in which you can do this:
83+
You now need to ensure that the kubectl completion script gets sourced in all
84+
your shell sessions. There are two ways in which you can do this:
7285
-->
7386
你现在需要确保一点:kubectl 补全脚本已经导入(sourced)到 Shell 会话中。
7487
可以通过以下两种方法进行设置:
@@ -79,6 +92,7 @@ echo 'source <(kubectl completion bash)' >>~/.bashrc
7992
{{< /tab >}}
8093
{{< tab name="系统全局" codelang="bash" >}}
8194
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
95+
sudo chmod a+r /etc/bash_completion.d/kubectl
8296
{{< /tab >}}
8397
{{< /tabs >}}
8498

content/zh-cn/docs/tasks/tools/included/optional-kubectl-configs-bash-mac.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ _build:
2323
### 简介 {#introduction}
2424

2525
<!--
26-
The kubectl completion script for Bash can be generated with `kubectl completion bash`. Sourcing this script in your shell enables kubectl completion.
26+
The kubectl completion script for Bash can be generated with `kubectl completion bash`.
27+
Sourcing this script in your shell enables kubectl completion.
2728
28-
However, the kubectl completion script depends on [**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install.
29+
However, the kubectl completion script depends on
30+
[**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install.
2931
-->
3032
kubectl 的 Bash 补全脚本可以通过 `kubectl completion bash` 命令生成。
3133
在你的 Shell 中导入(Sourcing)这个脚本即可启用补全功能。
@@ -35,10 +37,17 @@ kubectl 的 Bash 补全脚本可以通过 `kubectl completion bash` 命令生成
3537

3638
{{< warning>}}
3739
<!--
38-
There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2 (which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion script **doesn't work** correctly with bash-completion v1 and Bash 3.2. It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to correctly use kubectl completion on macOS, you have to install and use Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)). The following instructions assume that you use Bash 4.1+ (that is, any Bash version of 4.1 or newer).
39-
-->
40-
bash-completion 有两个版本:v1 和 v2。v1 对应 Bash 3.2(也是 macOS 的默认安装版本),v2 对应 Bash 4.1+。
41-
kubectl 的补全脚本**无法适配** bash-completion v1 和 Bash 3.2。
40+
There are two versions of bash-completion, v1 and v2. V1 is for Bash 3.2
41+
(which is the default on macOS), and v2 is for Bash 4.1+. The kubectl completion
42+
script **doesn't work** correctly with bash-completion v1 and Bash 3.2.
43+
It requires **bash-completion v2** and **Bash 4.1+**. Thus, to be able to
44+
correctly use kubectl completion on macOS, you have to install and use
45+
Bash 4.1+ ([*instructions*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)).
46+
The following instructions assume that you use Bash 4.1+
47+
(that is, any Bash version of 4.1 or newer).
48+
-->
49+
bash-completion 有两个版本:v1 和 v2。v1 对应 Bash 3.2(也是 macOS 的默认安装版本),
50+
v2 对应 Bash 4.1+。kubectl 的补全脚本**无法适配** bash-completion v1 和 Bash 3.2。
4251
必须为它配备 **bash-completion v2****Bash 4.1+**
4352
有鉴于此,为了在 macOS 上使用 kubectl 补全功能,你必须要安装和使用 Bash 4.1+
4453
[**说明**](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba))。
@@ -89,14 +98,17 @@ Homebrew 通常把它安装为 `/usr/local/bin/bash`。
8998

9099
{{< note >}}
91100
<!--
92-
As mentioned, these instructions assume you use Bash 4.1+, which means you will install bash-completion v2 (in contrast to Bash 3.2 and bash-completion v1, in which case kubectl completion won't work).
101+
As mentioned, these instructions assume you use Bash 4.1+, which means you will
102+
install bash-completion v2 (in contrast to Bash 3.2 and bash-completion v1,
103+
in which case kubectl completion won't work).
93104
-->
94105
如前所述,本说明假定你使用的 Bash 版本为 4.1+,这意味着你要安装 bash-completion v2
95106
(不同于 Bash 3.2 和 bash-completion v1,kubectl 的补全功能在该场景下无法工作)。
96107
{{< /note >}}
97108

98109
<!--
99-
You can test if you have bash-completion v2 already installed with `type _init_completion`. If not, you can install it with Homebrew:
110+
You can test if you have bash-completion v2 already installed with `type _init_completion`.
111+
If not, you can install it with Homebrew:
100112
-->
101113
你可以用命令 `type _init_completion` 测试 bash-completion v2 是否已经安装。
102114
如未安装,用 Homebrew 来安装它:
@@ -125,7 +137,8 @@ Reload your shell and verify that bash-completion v2 is correctly installed with
125137
### 启用 kubectl 自动补全功能 {#enable-kubectl-autocompletion}
126138

127139
<!--
128-
You now have to ensure that the kubectl completion script gets sourced in all your shell sessions. There are multiple ways to achieve this:
140+
You now have to ensure that the kubectl completion script gets sourced in all
141+
your shell sessions. There are multiple ways to achieve this:
129142
130143
- Source the completion script in your `~/.bash_profile` file:
131144
-->
@@ -158,7 +171,10 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
158171
```
159172

160173
<!--
161-
- If you installed kubectl with Homebrew (as explained [here](/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)), then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`. In that case, you don't need to do anything.
174+
- If you installed kubectl with Homebrew (as explained
175+
[here](/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)),
176+
then the kubectl completion script should already be in `/usr/local/etc/bash_completion.d/kubectl`.
177+
In that case, you don't need to do anything.
162178
-->
163179
- 如果你是用 Homebrew 安装的 kubectl
164180
(如[此页面](/zh-cn/docs/tasks/tools/install-kubectl-macos/#install-with-homebrew-on-macos)所描述),
@@ -167,7 +183,8 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
167183

168184
{{< note >}}
169185
<!--
170-
The Homebrew installation of bash-completion v2 sources all the files in the `BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work.
186+
The Homebrew installation of bash-completion v2 sources all the files in the
187+
`BASH_COMPLETION_COMPAT_DIR` directory, that's why the latter two methods work.
171188
-->
172189
用 Hommbrew 安装的 bash-completion v2 会初始化目录 `BASH_COMPLETION_COMPAT_DIR`
173190
中的所有文件,这就是后两种方法能正常工作的原因。
@@ -177,4 +194,3 @@ You now have to ensure that the kubectl completion script gets sourced in all yo
177194
In any case, after reloading your shell, kubectl completion should be working.
178195
-->
179196
总之,重新加载 Shell 之后,kubectl 补全功能将立即生效。
180-

content/zh-cn/docs/tasks/tools/install-kubectl-macos.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ card:
2222
## {{% heading "prerequisites" %}}
2323

2424
<!--
25-
You must use a kubectl version that is within one minor version difference of your cluster. For example, a v{{< skew currentVersion >}} client can communicate with v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}}, and v{{< skew currentVersionAddMinor 1 >}} control planes.
25+
You must use a kubectl version that is within one minor version difference of
26+
your cluster. For example, a v{{< skew currentVersion >}} client can communicate
27+
with v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}},
28+
and v{{< skew currentVersionAddMinor 1 >}} control planes.
2629
Using the latest compatible version of kubectl helps avoid unforeseen issues.
2730
-->
2831
kubectl 版本和集群之间的差异必须在一个小版本号之内。
@@ -80,7 +83,8 @@ The following methods exist for installing kubectl on macOS:
8083

8184
{{< note >}}
8285
<!--
83-
To download a specific version, replace the `$(curl -L -s https://dl.k8s.io/release/stable.txt)` portion of the command with the specific version.
86+
To download a specific version, replace the `$(curl -L -s https://dl.k8s.io/release/stable.txt)`
87+
portion of the command with the specific version.
8488
8589
For example, to download version {{< param "fullversion" >}} on Intel macOS, type:
8690
-->
@@ -193,6 +197,7 @@ The following methods exist for installing kubectl on macOS:
193197
The above command will generate a warning:
194198
-->
195199
上面的命令会产生一个警告:
200+
196201
```
197202
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.
198203
```
@@ -226,7 +231,8 @@ The following methods exist for installing kubectl on macOS:
226231
### 用 Homebrew 在 macOS 系统上安装 {#install-with-homebrew-on-macos}
227232

228233
<!--
229-
If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you can install kubectl with Homebrew.
234+
If you are on macOS and using [Homebrew](https://brew.sh/) package manager,
235+
you can install kubectl with Homebrew.
230236
-->
231237
如果你是 macOS 系统,且用的是 [Homebrew](https://brew.sh/) 包管理工具,
232238
则可以用 Homebrew 安装 kubectl。
@@ -262,7 +268,8 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you
262268
### 用 Macports 在 macOS 系统上安装 {#install-with-macports-on-macos}
263269

264270
<!--
265-
If you are on macOS and using [Macports](https://macports.org/) package manager, you can install kubectl with Macports.
271+
If you are on macOS and using [Macports](https://macports.org/) package manager,
272+
you can install kubectl with Macports.
266273
-->
267274
如果你用的是 macOS,且用 [Macports](https://macports.org/) 包管理工具,则你可以用 Macports 安装 kubectl。
268275

@@ -302,7 +309,8 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
302309
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
303310

304311
<!--
305-
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell which can save you a lot of typing.
312+
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell
313+
which can save you a lot of typing.
306314
307315
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
308316
-->
@@ -433,7 +441,7 @@ kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以
433441
<!--
434442
1. After installing the plugin, clean up the installation files:
435443
-->
436-
1. 安装插件后,清理安装文件:
444+
6. 安装插件后,清理安装文件:
437445

438446
```bash
439447
rm kubectl-convert kubectl-convert.sha256

content/zh-cn/docs/tasks/tools/install-kubectl-windows.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ card:
2222
## {{% heading "prerequisites" %}}
2323

2424
<!--
25-
You must use a kubectl version that is within one minor version difference of your cluster. For example, a v{{< skew currentVersion >}} client can communicate with v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}}, and v{{< skew currentVersionAddMinor 1 >}} control planes.
25+
You must use a kubectl version that is within one minor version difference of
26+
your cluster. For example, a v{{< skew currentVersion >}} client can communicate
27+
with v{{< skew currentVersionAddMinor -1 >}}, v{{< skew currentVersionAddMinor 0 >}},
28+
and v{{< skew currentVersionAddMinor 1 >}} control planes.
2629
Using the latest compatible version of kubectl helps avoid unforeseen issues.
2730
-->
2831
kubectl 版本和集群版本之间的差异必须在一个小版本号内。
@@ -67,7 +70,8 @@ The following methods exist for installing kubectl on Windows:
6770

6871
{{< note >}}
6972
<!--
70-
To find out the latest stable version (for example, for scripting), take a look at [https://dl.k8s.io/release/stable.txt](https://dl.k8s.io/release/stable.txt).
73+
To find out the latest stable version (for example, for scripting), take a look at
74+
[https://dl.k8s.io/release/stable.txt](https://dl.k8s.io/release/stable.txt).
7175
-->
7276
要想找到最新稳定的版本(例如:为了编写脚本),可以看看这里 [https://dl.k8s.io/release/stable.txt](https://dl.k8s.io/release/stable.txt)
7377
{{< /note >}}
@@ -101,7 +105,8 @@ The following methods exist for installing kubectl on Windows:
101105
```
102106
103107
<!--
104-
- Using PowerShell to automate the verification using the `-eq` operator to get a `True` or `False` result:
108+
- Using PowerShell to automate the verification using the `-eq` operator to
109+
get a `True` or `False` result:
105110
-->
106111
- 用 PowerShell 自动验证,用运算符 `-eq` 来直接取得 `True` 或 `False` 的结果:
107112
@@ -127,9 +132,11 @@ The following methods exist for installing kubectl on Windows:
127132
The above command will generate a warning:
128133
-->
129134
上面的命令会产生一个警告:
135+
130136
```
131137
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.
132138
```
139+
133140
<!--
134141
You can ignore this warning. You are only checking the version of `kubectl` that you
135142
have installed.
@@ -157,8 +164,10 @@ The following methods exist for installing kubectl on Windows:
157164

158165
{{< note >}}
159166
<!--
160-
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to `PATH`.
161-
If you have installed Docker Desktop before, you may need to place your `PATH` entry before the one added by the Docker Desktop installer or remove the Docker Desktop's `kubectl`.
167+
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes)
168+
adds its own version of `kubectl` to `PATH`. If you have installed Docker Desktop before,
169+
you may need to place your `PATH` entry before the one added by the Docker Desktop
170+
installer or remove the Docker Desktop's `kubectl`.
162171
-->
163172
[Windows 版的 Docker Desktop](https://docs.docker.com/docker-for-windows/#kubernetes)
164173
将其自带版本的 `kubectl` 添加到 `PATH`
@@ -172,7 +181,9 @@ If you have installed Docker Desktop before, you may need to place your `PATH` e
172181
### 在 Windows 上用 Chocolatey、Scoop 或 winget 安装 {#install-nonstandard-package-tools}
173182

174183
<!--
175-
1. To install kubectl on Windows you can use either [Chocolatey](https://chocolatey.org) package manager, [Scoop](https://scoop.sh) command-line installer, or [winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) package manager.
184+
1. To install kubectl on Windows you can use either [Chocolatey](https://chocolatey.org)
185+
package manager, [Scoop](https://scoop.sh) command-line installer, or
186+
[winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/) package manager.
176187
-->
177188
1. 要在 Windows 上安装 kubectl,你可以使用包管理器 [Chocolatey](https://chocolatey.org)
178189
命令行安装器 [Scoop](https://scoop.sh) 或包管理器 [winget](https://learn.microsoft.com/zh-cn/windows/package-manager/winget/)
@@ -265,7 +276,8 @@ Edit the config file with a text editor of your choice, such as Notepad.
265276
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
266277

267278
<!--
268-
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell, which can save you a lot of typing.
279+
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell,
280+
which can save you a lot of typing.
269281
270282
Below are the procedures to set up autocompletion for PowerShell.
271283
-->

0 commit comments

Comments
 (0)