@@ -5,7 +5,7 @@ weight: 10
5
5
card :
6
6
name : tasks
7
7
weight : 20
8
- title : 在 macOS 系统上安装 kubectl
8
+ title : 在 macOS 系统上安装 kubectl
9
9
---
10
10
<!--
11
11
reviewers:
21
21
22
22
## {{% heading "prerequisites" %}}
23
23
24
- <!--
24
+ <!--
25
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.
26
26
Using the latest compatible version of kubectl helps avoid unforeseen issues.
27
27
-->
@@ -30,31 +30,40 @@ kubectl 版本和集群之间的差异必须在一个小版本号之内。
30
30
v{{< skew currentVersionAddMinor 0 >}} 和 v{{< skew currentVersionAddMinor 1 >}} 版本的控制面通信。
31
31
用最新兼容版本的 kubectl 有助于避免不可预见的问题。
32
32
33
- <!--
33
+ <!--
34
34
## Install kubectl on macOS
35
35
-->
36
36
## 在 macOS 系统上安装 kubectl {#install-kubectl-on-macos}
37
37
38
- <!--
38
+ <!--
39
39
The following methods exist for installing kubectl on macOS:
40
40
-->
41
41
在 macOS 系统上安装 kubectl 有如下方法:
42
42
43
43
<!--
44
- - [Install kubectl binary with curl on macOS](#install-kubectl-binary-with-curl-on-macos)
45
- - [Install with Homebrew on macOS](#install-with-homebrew-on-macos)
46
- - [Install with Macports on macOS](#install-with-macports-on-macos)
44
+ - [Install kubectl on macOS](#install-kubectl-on-macos)
45
+ - [Install kubectl binary with curl on macOS](#install-kubectl-binary-with-curl-on-macos)
46
+ - [Install with Homebrew on macOS](#install-with-homebrew-on-macos)
47
+ - [Install with Macports on macOS](#install-with-macports-on-macos)
48
+ - [Verify kubectl configuration](#verify-kubectl-configuration)
49
+ - [Optional kubectl configurations and plugins](#optional-kubectl-configurations-and-plugins)
50
+ - [Enable shell autocompletion](#enable-shell-autocompletion)
51
+ - [Install `kubectl convert` plugin](#install-kubectl-convert-plugin)
47
52
-->
48
- - [ 用 curl 在 macOS 系统上安装 kubectl] ( #install-kubectl-binary-with-curl-on-macos )
49
- - [ 用 Homebrew 在 macOS 系统上安装] ( #install-with-homebrew-on-macos )
50
- - [ 用 Macports 在 macOS 上安装] ( #install-with-macports-on-macos )
51
-
53
+ - [ 在 macOS 系统上安装 kubectl] ( #install-kubectl-on-macos )
54
+ - [ 用 curl 在 macOS 系统上安装 kubectl] ( #install-kubectl-binary-with-curl-on-macos )
55
+ - [ 用 Homebrew 在 macOS 系统上安装] ( #install-with-homebrew-on-macos )
56
+ - [ 用 Macports 在 macOS 系统上安装] ( #install-with-macports-on-macos )
57
+ - [ 验证 kubectl 配置] ( #verify-kubectl-configuration )
58
+ - [ 可选的 kubectl 配置和插件] ( #optional-kubectl-configurations-and-plugins )
59
+ - [ 启用 shell 自动补全功能] ( #enable-shell-autocompletion )
60
+ - [ 安装 ` kubectl convert ` 插件] ( #install-kubectl-convert-plugin )
52
61
<!--
53
62
### Install kubectl binary with curl on macOS
54
63
-->
55
64
### 用 curl 在 macOS 系统上安装 kubectl {#install-kubectl-binary-with-curl-on-macos}
56
65
57
- <!--
66
+ <!--
58
67
1. Download the latest release:
59
68
-->
60
69
1 . 下载最新的发行版:
@@ -69,7 +78,7 @@ The following methods exist for installing kubectl on macOS:
69
78
{{< /tabs >}}
70
79
71
80
{{< note >}}
72
- <!--
81
+ <!--
73
82
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.
74
83
75
84
For example, to download version {{< param "fullversion" >}} on Intel macOS, type:
@@ -91,7 +100,7 @@ The following methods exist for installing kubectl on macOS:
91
100
```
92
101
{{< /note >}}
93
102
94
- <!--
103
+ <!--
95
104
1. Validate the binary (optional)
96
105
97
106
Download the kubectl checksum file:
@@ -109,7 +118,7 @@ The following methods exist for installing kubectl on macOS:
109
118
{{< /tab >}}
110
119
{{< /tabs >}}
111
120
112
- <!--
121
+ <!--
113
122
Validate the kubectl binary against the checksum file:
114
123
-->
115
124
根据校验和文件,验证 kubectl:
@@ -126,7 +135,7 @@ The following methods exist for installing kubectl on macOS:
126
135
kubectl: OK
127
136
```
128
137
129
- <!--
138
+ <!--
130
139
If the check fails, `shasum` exits with nonzero status and prints output similar to:
131
140
-->
132
141
验证失败时,` shasum ` 将以非零值退出,并打印如下输出:
@@ -137,13 +146,13 @@ The following methods exist for installing kubectl on macOS:
137
146
```
138
147
139
148
{{< note >}}
140
- <!--
149
+ <!--
141
150
Download the same version of the binary and checksum.
142
151
-->
143
152
下载的 kubectl 与校验和文件版本要相同。
144
153
{{< /note >}}
145
154
146
- <!--
155
+ <!--
147
156
1. Make the kubectl binary executable.
148
157
-->
149
158
3 . 将 kubectl 置为可执行文件:
@@ -152,7 +161,7 @@ The following methods exist for installing kubectl on macOS:
152
161
chmod +x ./kubectl
153
162
```
154
163
155
- <!--
164
+ <!--
156
165
1. Move the kubectl binary to a file location on your system `PATH`.
157
166
-->
158
167
4 . 将可执行文件 kubectl 移动到系统可寻址路径 ` PATH ` 内的一个位置:
@@ -169,7 +178,7 @@ The following methods exist for installing kubectl on macOS:
169
178
确保 ` /usr/local/bin ` 在你的 PATH 环境变量中。
170
179
{{< /note >}}
171
180
172
- <!--
181
+ <!--
173
182
1. Test to ensure the version you installed is up-to-date:
174
183
-->
175
184
5 . 测试一下,确保你安装的是最新的版本:
@@ -187,33 +196,42 @@ The following methods exist for installing kubectl on macOS:
187
196
kubectl version --client --output=yaml
188
197
```
189
198
199
+ <!--
200
+ 1. After installing the plugin, clean up the installation files:
201
+ -->
202
+ 1 . 安装插件后,清理安装文件:
203
+
204
+ ``` bash
205
+ rm kubectl kubectl.sha256
206
+ ```
190
207
<!--
191
208
### Install with Homebrew on macOS
192
209
-->
193
210
### 用 Homebrew 在 macOS 系统上安装 {#install-with-homebrew-on-macos}
194
211
195
- <!--
212
+ <!--
196
213
If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you can install kubectl with Homebrew.
197
214
-->
198
215
如果你是 macOS 系统,且用的是 [ Homebrew] ( https://brew.sh/ ) 包管理工具,
199
216
则可以用 Homebrew 安装 kubectl。
200
217
201
- <!--
218
+ <!--
202
219
1. Run the installation command:
203
220
-->
204
221
1 . 运行安装命令:
205
222
206
223
``` bash
207
- brew install kubectl
224
+ brew install kubectl
208
225
```
209
226
227
+ <!-- or -->
210
228
或
211
229
212
230
``` bash
213
231
brew install kubernetes-cli
214
232
```
215
233
216
- <!--
234
+ <!--
217
235
1. Test to ensure the version you installed is up-to-date:
218
236
-->
219
237
2 . 测试一下,确保你安装的是最新的版本:
@@ -222,17 +240,17 @@ If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you
222
240
kubectl version --client
223
241
```
224
242
225
- <!--
243
+ <!--
226
244
### Install with Macports on macOS
227
245
-->
228
- ### 用 Macports 在 macOS 上安装 {#install-with-macports-on-macos}
246
+ ### 用 Macports 在 macOS 系统上安装 {#install-with-macports-on-macos}
229
247
230
- <!--
248
+ <!--
231
249
If you are on macOS and using [Macports](https://macports.org/) package manager, you can install kubectl with Macports.
232
250
-->
233
- 如果你用的是 macOS,且用 [ Macports] ( https://macports.org/ ) 包管理工具,则你可以用 Macports 安装kubectl 。
251
+ 如果你用的是 macOS,且用 [ Macports] ( https://macports.org/ ) 包管理工具,则你可以用 Macports 安装 kubectl 。
234
252
235
- <!--
253
+ <!--
236
254
1. Run the installation command:
237
255
-->
238
256
1 . 运行安装命令:
@@ -242,7 +260,7 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
242
260
sudo port install kubectl
243
261
```
244
262
245
- <!--
263
+ <!--
246
264
1. Test to ensure the version you installed is up-to-date:
247
265
-->
248
266
2 . 测试一下,确保你安装的是最新的版本:
@@ -251,14 +269,14 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
251
269
kubectl version --client
252
270
```
253
271
254
- <!--
272
+ <!--
255
273
## Verify kubectl configuration
256
274
-->
257
275
## 验证 kubectl 配置 {#verify-kubectl-configuration}
258
276
259
277
{{< include "included/verify-kubectl.md" >}}
260
278
261
- <!--
279
+ <!--
262
280
## Optional kubectl configurations and plugins
263
281
264
282
### Enable shell autocompletion
@@ -267,7 +285,7 @@ If you are on macOS and using [Macports](https://macports.org/) package manager,
267
285
268
286
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
269
287
270
- <!--
288
+ <!--
271
289
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell which can save you a lot of typing.
272
290
273
291
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
@@ -309,7 +327,7 @@ kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以
309
327
Download the kubectl-convert checksum file:
310
328
-->
311
329
2 . 验证该可执行文件(可选步骤)
312
-
330
+
313
331
下载 kubectl-convert 校验和文件:
314
332
315
333
{{< tabs name="download_convert_checksum_macos" >}}
@@ -329,7 +347,7 @@ kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以
329
347
``` bash
330
348
echo " $( cat kubectl-convert.sha256) kubectl-convert" | shasum -a 256 --check
331
349
```
332
-
350
+
333
351
<!--
334
352
If valid, the output is:
335
353
-->
@@ -396,7 +414,15 @@ kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以
396
414
-->
397
415
如果你没有看到任何错误就代表插件安装成功了。
398
416
417
+ <!--
418
+ 1. After installing the plugin, clean up the installation files:
419
+ -->
420
+ 1 . 安装插件后,清理安装文件:
421
+
422
+ ``` bash
423
+ rm kubectl kubectl.sha256
424
+ ```
425
+
399
426
## {{% heading "whatsnext" %}}
400
427
401
428
{{< include "included/kubectl-whats-next.md" >}}
402
-
0 commit comments