Switch language name 'zh' to 'zh-cn'
This is the first step to rename 'zh' to 'zh-cn'. There are several reasons why we rename the language name.
- The upstream docsy theme changed the language name, leading to many warnings during site build;
The side-effect is that the i18n strings are no longer working.
- We believe renaming the language is the right thing to do, because this move can make room for other variants of Chinese language, such as 'zh-tw', 'zh-sg' etc.
There would be several follow-ups to this PR, such as fixing the intra-site links, adding redirects etc.
We will lock up changes to zh/zh-cn pages for the moment, until this one gets in.
This PR is based on commit cdad0a7342.
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
---
|
||||
title: "安装工具"
|
||||
weight: 10
|
||||
description: 在你的计算机上设置 Kubernetes 工具。
|
||||
no_list: true
|
||||
---
|
||||
|
||||
<!--
|
||||
title: "Install Tools"
|
||||
description: Set up Kubernetes tools on your computer.
|
||||
weight: 10
|
||||
no_list: true
|
||||
-->
|
||||
|
||||
<!--
|
||||
## kubectl
|
||||
|
||||
The Kubernetes command-line tool, [kubectl](/docs/reference/kubectl/kubectl/), allows
|
||||
you to run commands against Kubernetes clusters.
|
||||
You can use kubectl to deploy applications, inspect and manage cluster resources,
|
||||
and view logs. For more information including a complete list of kubectl operations, see the
|
||||
[`kubectl` reference documentation](/docs/reference/kubectl/).
|
||||
-->
|
||||
## kubectl
|
||||
|
||||
Kubernetes 命令行工具,[kubectl](/docs/reference/kubectl/kubectl/),使得你可以对 Kubernetes 集群运行命令。
|
||||
你可以使用 kubectl 来部署应用、监测和管理集群资源以及查看日志。
|
||||
|
||||
有关更多信息,包括 kubectl 操作的完整列表,请参见[`kubectl`
|
||||
参考文件](/zh/docs/reference/kubectl/)。
|
||||
|
||||
<!--
|
||||
kubectl is installable on a variety of Linux platforms, macOS and Windows.
|
||||
Find your preferred operating system below.
|
||||
|
||||
- [Install kubectl on Linux](/docs/tasks/tools/install-kubectl-linux)
|
||||
- [Install kubectl on macOS](/docs/tasks/tools/install-kubectl-macos)
|
||||
- [Install kubectl on Windows](/docs/tasks/tools/install-kubectl-windows)
|
||||
-->
|
||||
kubectl 可安装在各种 Linux 平台、 macOS 和 Windows 上。
|
||||
在下面找到你喜欢的操作系统。
|
||||
|
||||
- [在 Linux 上安装 kubectl](/zh/docs/tasks/tools/install-kubectl-linux)
|
||||
- [在 macOS 上安装 kubectl](/zh/docs/tasks/tools/install-kubectl-macos)
|
||||
- [在 Windows 上安装 kubectl](/zh/docs/tasks/tools/install-kubectl-windows)
|
||||
|
||||
<!--
|
||||
## kind
|
||||
|
||||
[`kind`](https://kind.sigs.k8s.io/docs/) lets you run Kubernetes on
|
||||
your local computer. This tool requires that you have
|
||||
[Docker](https://docs.docker.com/get-docker/) installed and configured.
|
||||
|
||||
The kind [Quick Start](https://kind.sigs.k8s.io/docs/user/quick-start/) page
|
||||
shows you what you need to do to get up and running with `kind`.
|
||||
|
||||
<a class="btn btn-primary" href="https://kind.sigs.k8s.io/docs/user/quick-start/" role="button" aria-label="View kind Quick Start Guide">View kind Quick Start Guide</a>
|
||||
|
||||
-->
|
||||
## kind
|
||||
|
||||
[`kind`](https://kind.sigs.k8s.io/docs/) 让你能够在本地计算机上运行 Kubernetes。
|
||||
`kind` 要求你安装并配置好 [Docker](https://docs.docker.com/get-docker/)。
|
||||
|
||||
kind [快速入门](https://kind.sigs.k8s.io/docs/user/quick-start/)页面展示了
|
||||
开始使用 `kind` 所需要完成的操作。
|
||||
|
||||
<a class="btn btn-primary" href="https://kind.sigs.k8s.io/docs/user/quick-start/"
|
||||
role="button" aria-label="查看 kind 的快速入门指南">
|
||||
查看 kind 的快速入门指南
|
||||
</a>
|
||||
|
||||
<!--
|
||||
## minikube
|
||||
|
||||
Like `kind`, [`minikube`](https://minikube.sigs.k8s.io/) is a tool that lets you run Kubernetes
|
||||
locally. `minikube` runs a single-node Kubernetes cluster on your personal
|
||||
computer (including Windows, macOS and Linux PCs) so that you can try out
|
||||
Kubernetes, or for daily development work.
|
||||
|
||||
You can follow the official
|
||||
[Get Started!](https://minikube.sigs.k8s.io/docs/start/) guide if your focus is
|
||||
on getting the tool installed.
|
||||
-->
|
||||
## minikube
|
||||
|
||||
与 `kind` 类似,[`minikube`](https://minikube.sigs.k8s.io/) 是一个工具,
|
||||
能让你在本地运行 Kubernetes。
|
||||
`minikube` 在你本地的个人计算机(包括 Windows、macOS 和 Linux PC)运行一个单节点的
|
||||
Kubernetes 集群,以便你来尝试 Kubernetes 或者开展每天的开发工作。
|
||||
|
||||
如果你关注如何安装此工具,可以按官方的
|
||||
[Get Started!](https://minikube.sigs.k8s.io/docs/start/)指南操作。
|
||||
|
||||
<!--
|
||||
a class="btn btn-primary" href="https://minikube.sigs.k8s.io/docs/start/" role="button" aria-label="View minikube Get Started! Guide">View minikube Get Started! Guide</a>
|
||||
|
||||
Once you have `minikube` working, you can use it to
|
||||
[run a sample application](/docs/tutorials/hello-minikube/).
|
||||
-->
|
||||
<a class="btn btn-primary" href="https://minikube.sigs.k8s.io/docs/start/"
|
||||
role="button" aria-label="查看 minikube 快速入门指南">
|
||||
查看 minikube 快速入门指南
|
||||
</a>
|
||||
|
||||
当你拥有了可工作的 `minikube` 时,就可以用它来
|
||||
[运行示例应用](/zh/docs/tutorials/hello-minikube/)了。
|
||||
|
||||
## kubeadm
|
||||
|
||||
<!--
|
||||
You can use the {{< glossary_tooltip term_id="kubeadm" text="kubeadm" >}} tool to create and manage Kubernetes clusters.
|
||||
It performs the actions necessary to get a minimum viable, secure cluster up and running in a user friendly way.
|
||||
-->
|
||||
你可以使用 {{< glossary_tooltip term_id="kubeadm" text="kubeadm" >}} 工具来
|
||||
创建和管理 Kubernetes 集群。
|
||||
该工具能够执行必要的动作并用一种用户友好的方式启动一个可用的、安全的集群。
|
||||
|
||||
<!--
|
||||
[Installing kubeadm](/docs/setup/production-environment/tools/kubeadm/install-kubeadm/) shows you how to install kubeadm.
|
||||
Once installed, you can use it to [create a cluster](/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/).
|
||||
-->
|
||||
[安装 kubeadm](/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/)
|
||||
展示了如何安装 kubeadm 的过程。
|
||||
一旦安装了 kubeadm,你就可以使用它来
|
||||
[创建一个集群](/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/)。
|
||||
|
||||
<!-- a class="btn btn-primary" href="/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" role="button" aria-label="View kubeadm Install Guide">View kubeadm Install Guide</a-->
|
||||
|
||||
<a class="btn btn-primary" href="/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/"
|
||||
role="button" aria-label="查看 kubeadm 安装指南">查看 kubeadm 安装指南</a>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
title: "内含的工具"
|
||||
description: "在页面 kubectl-installs-*.md 中包含的代码片段"
|
||||
headless: true
|
||||
toc_hide: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "Tools Included"
|
||||
description: "Snippets to be included in the main kubectl-installs-*.md pages."
|
||||
headless: true
|
||||
toc_hide: true
|
||||
---
|
||||
-->
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
title: "kubectl-convert 概述"
|
||||
description: >-
|
||||
一个 kubectl 插件,允许你将清单从一个 Kubernetes API 版本转换到不同的版本。
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "kubectl-convert overview"
|
||||
description: >-
|
||||
A kubectl plugin that allows you to convert manifests from one version
|
||||
of a Kubernetes API to a different version.
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
A plugin for Kubernetes command-line tool `kubectl`, which allows you to convert manifests between different API
|
||||
versions. This can be particularly helpful to migrate manifests to a non-deprecated api version with newer Kubernetes release.
|
||||
For more info, visit [migrate to non deprecated apis](/docs/reference/using-api/deprecation-guide/#migrate-to-non-deprecated-apis)
|
||||
-->
|
||||
一个 Kubernetes 命令行工具 `kubectl` 的插件,允许你将清单在不同 API 版本间转换。
|
||||
这对于将清单迁移到新的 Kubernetes 发行版上未被废弃的 API 版本时尤其有帮助。
|
||||
更多信息请访问 [迁移到非弃用 API](/zh/docs/reference/using-api/deprecation-guide/#migrate-to-non-deprecated-apis)
|
||||
@@ -0,0 +1,27 @@
|
||||
---
|
||||
title: "后续内容"
|
||||
description: "安装 kubectl 之后,还可以做些什么?"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "What's next?"
|
||||
description: "What's next after installing kubectl."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
* [Install Minikube](https://minikube.sigs.k8s.io/docs/start/)
|
||||
* See the [getting started guides](/docs/setup/) for more about creating clusters.
|
||||
* [Learn how to launch and expose your application.](/docs/tasks/access-application-cluster/service-access-application-cluster/)
|
||||
* If you need access to a cluster you didn't create, see the
|
||||
[Sharing Cluster Access document](/docs/tasks/access-application-cluster/configure-access-multiple-clusters/).
|
||||
* Read the [kubectl reference docs](/docs/reference/kubectl/kubectl/)
|
||||
-->
|
||||
* [安装 Minikube](https://minikube.sigs.k8s.io/docs/start/)
|
||||
* 有关创建集群的更多信息,请参阅[入门指南](/zh/docs/setup/).
|
||||
* [学习如何启动并对外公开你的应用程序。](/zh/docs/tasks/access-application-cluster/service-access-application-cluster/)
|
||||
* 如果你需要访问其他人创建的集群,请参阅
|
||||
[共享集群接入文档](/zh/docs/tasks/access-application-cluster/configure-access-multiple-clusters/).
|
||||
* 阅读 [kubectl 参考文档](/zh/docs/reference/kubectl/kubectl/)
|
||||
@@ -0,0 +1,102 @@
|
||||
---
|
||||
title: "Linux 系统中的 bash 自动补全功能"
|
||||
description: "Linux 系统中 bash 自动补全功能的一些可选配置。"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "bash auto-completion on Linux"
|
||||
description: "Some optional configuration for bash auto-completion on Linux."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
### Introduction
|
||||
-->
|
||||
### 简介 {#introduction}
|
||||
|
||||
<!--
|
||||
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.
|
||||
|
||||
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`).
|
||||
-->
|
||||
kubectl 的 Bash 补全脚本可以用命令 `kubectl completion bash` 生成。
|
||||
在 shell 中导入(Sourcing)补全脚本,将启用 kubectl 自动补全功能。
|
||||
|
||||
然而,补全脚本依赖于工具 [**bash-completion**](https://github.com/scop/bash-completion),
|
||||
所以要先安装它(可以用命令 `type _init_completion` 检查 bash-completion 是否已安装)。
|
||||
|
||||
<!--
|
||||
### Install bash-completion
|
||||
-->
|
||||
### 安装 bash-completion {#install-bash-comletion}
|
||||
|
||||
<!--
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
-->
|
||||
很多包管理工具均支持 bash-completion(参见[这里](https://github.com/scop/bash-completion#installation))。
|
||||
可以通过 `apt-get install bash-completion` 或 `yum install bash-completion` 等命令来安装它。
|
||||
|
||||
上述命令将创建文件 `/usr/share/bash-completion/bash_completion`,它是 bash-completion 的主脚本。
|
||||
依据包管理工具的实际情况,你需要在 `~/.bashrc` 文件中手工导入此文件。
|
||||
|
||||
要查看结果,请重新加载你的 shell,并运行命令 `type _init_completion`。
|
||||
如果命令执行成功,则设置完成,否则将下面内容添加到文件 `~/.bashrc` 中:
|
||||
|
||||
```bash
|
||||
source /usr/share/bash-completion/bash_completion
|
||||
```
|
||||
|
||||
<!--
|
||||
Reload your shell and verify that bash-completion is correctly installed by typing `type _init_completion`.
|
||||
-->
|
||||
重新加载 shell,再输入命令 `type _init_completion` 来验证 bash-completion 的安装状态。
|
||||
|
||||
<!--
|
||||
### Enable kubectl autocompletion
|
||||
-->
|
||||
### 启动 kubectl 自动补全功能 {#enable-kubectl-autocompletion}
|
||||
|
||||
#### Bash
|
||||
|
||||
<!--
|
||||
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:
|
||||
-->
|
||||
你现在需要确保一点:kubectl 补全脚本已经导入(sourced)到 shell 会话中。
|
||||
可以通过以下两种方法进行设置:
|
||||
|
||||
{{< tabs name="kubectl_bash_autocompletion" >}}
|
||||
{{{< tab name="当前用户" codelang="bash" >}}
|
||||
echo 'source <(kubectl completion bash)' >>~/.bashrc
|
||||
{{< /tab >}}
|
||||
{{< tab name="系统全局" codelang="bash" >}}
|
||||
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
|
||||
{{< /tab >}}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
If you have an alias for kubectl, you can extend shell completion to work with that alias:
|
||||
-->
|
||||
如果 kubectl 有关联的别名,你可以扩展 shell 补全来适配此别名:
|
||||
|
||||
```bash
|
||||
echo 'alias k=kubectl' >>~/.bashrc
|
||||
echo 'complete -F __start_kubectl k' >>~/.bashrc
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
bash-completion sources all completion scripts in `/etc/bash_completion.d`.
|
||||
-->
|
||||
bash-completion 负责导入 `/etc/bash_completion.d` 目录中的所有补全脚本。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
Both approaches are equivalent. After reloading your shell, kubectl autocompletion should be working.
|
||||
-->
|
||||
两种方式的效果相同。重新加载 shell 后,kubectl 自动补全功能即可生效。
|
||||
@@ -0,0 +1,174 @@
|
||||
---
|
||||
title: "macOS 系统上的 bash 自动补全"
|
||||
description: "在 macOS 上实现 Bash 自动补全的一些可选配置。"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
title: "bash auto-completion on macOS"
|
||||
description: "Some optional configuration for bash auto-completion on macOS."
|
||||
headless: true
|
||||
-->
|
||||
|
||||
<!--
|
||||
### Introduction
|
||||
-->
|
||||
### 简介
|
||||
|
||||
<!--
|
||||
The kubectl completion script for Bash can be generated with `kubectl completion bash`. Sourcing this script in your shell enables kubectl completion.
|
||||
|
||||
However, the kubectl completion script depends on [**bash-completion**](https://github.com/scop/bash-completion) which you thus have to previously install.
|
||||
-->
|
||||
kubectl 的 Bash 补全脚本可以通过 `kubectl completion bash` 命令生成。
|
||||
在你的 shell 中导入(Sourcing)这个脚本即可启用补全功能。
|
||||
|
||||
此外,kubectl 补全脚本依赖于工具 [**bash-completion**](https://github.com/scop/bash-completion),
|
||||
所以你必须先安装它。
|
||||
|
||||
{{< warning>}}
|
||||
<!--
|
||||
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).
|
||||
-->
|
||||
bash-completion 有两个版本:v1 和 v2。v1 对应 Bash3.2(也是 macOS 的默认安装版本),v2 对应 Bash 4.1+。
|
||||
kubectl 的补全脚本**无法适配** bash-completion v1 和 Bash 3.2。
|
||||
必须为它配备 **bash-completion v2** 和 **Bash 4.1+**。
|
||||
有鉴于此,为了在 macOS 上使用 kubectl 补全功能,你必须要安装和使用 Bash 4.1+
|
||||
([*说明*](https://itnext.io/upgrading-bash-on-macos-7138bd1066ba))。
|
||||
后续说明假定你用的是 Bash 4.1+(也就是 Bash 4.1 或更新的版本)
|
||||
{{< /warning >}}
|
||||
|
||||
<!--
|
||||
### Upgrade Bash
|
||||
-->
|
||||
### 升级 Bash
|
||||
|
||||
<!--
|
||||
The instructions here assume you use Bash 4.1+. You can check your Bash's version by running:
|
||||
-->
|
||||
后续说明假定你已使用 Bash 4.1+。你可以运行以下命令检查 Bash 版本:
|
||||
|
||||
```bash
|
||||
echo $BASH_VERSION
|
||||
```
|
||||
|
||||
<!--
|
||||
If it is too old, you can install/upgrade it using Homebrew:
|
||||
-->
|
||||
如果版本太旧,可以用 Homebrew 安装/升级:
|
||||
|
||||
```bash
|
||||
brew install bash
|
||||
```
|
||||
|
||||
<!--
|
||||
Reload your shell and verify that the desired version is being used:
|
||||
-->
|
||||
重新加载 shell,并验证所需的版本已经生效:
|
||||
|
||||
```bash
|
||||
echo $BASH_VERSION $SHELL
|
||||
```
|
||||
|
||||
<!--
|
||||
Homebrew usually installs it at `/usr/local/bin/bash`.
|
||||
-->
|
||||
Homebrew 通常把它安装为 `/usr/local/bin/bash`。
|
||||
|
||||
<!--
|
||||
### Install bash-completion
|
||||
-->
|
||||
### 安装 bash-completion
|
||||
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
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).
|
||||
-->
|
||||
如前所述,本说明假定你使用的 Bash 版本为 4.1+,这意味着你要安装 bash-completion v2
|
||||
(不同于 Bash 3.2 和 bash-completion v1,kubectl 的补全功能在该场景下无法工作)。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
You can test if you have bash-completion v2 already installed with `type _init_completion`. If not, you can install it with Homebrew:
|
||||
-->
|
||||
你可以用命令 `type _init_completion` 测试 bash-completion v2 是否已经安装。
|
||||
如未安装,用 Homebrew 来安装它:
|
||||
|
||||
```bash
|
||||
brew install bash-completion@2
|
||||
```
|
||||
|
||||
<!--
|
||||
As stated in the output of this command, add the following to your `~/.bash_profile` file:
|
||||
-->
|
||||
如命令的输出信息所显示的,将如下内容添加到文件 `~/.bash_profile` 中:
|
||||
|
||||
```bash
|
||||
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
|
||||
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
|
||||
```
|
||||
|
||||
<!--
|
||||
Reload your shell and verify that bash-completion v2 is correctly installed with `type _init_completion`.
|
||||
-->
|
||||
重新加载 shell,并用命令 `type _init_completion` 验证 bash-completion v2 已经恰当的安装。
|
||||
|
||||
<!--
|
||||
### Enable kubectl autocompletion
|
||||
-->
|
||||
### 启用 kubectl 自动补全功能
|
||||
|
||||
<!--
|
||||
You now have to ensure that the kubectl completion script gets sourced in all your shell sessions. There are multiple ways to achieve this:
|
||||
|
||||
- Source the completion script in your `~/.bash_profile` file:
|
||||
-->
|
||||
你现在需要确保在所有的 shell 环境中均已导入(sourced) kubectl 的补全脚本,
|
||||
有若干种方法可以实现这一点:
|
||||
|
||||
- 在文件 `~/.bash_profile` 中导入(Source)补全脚本:
|
||||
|
||||
```bash
|
||||
echo 'source <(kubectl completion bash)' >>~/.bash_profile
|
||||
```
|
||||
|
||||
<!--
|
||||
- Add the completion script to the `/usr/local/etc/bash_completion.d` directory:
|
||||
-->
|
||||
- 将补全脚本添加到目录 `/usr/local/etc/bash_completion.d` 中:
|
||||
|
||||
```bash
|
||||
kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl
|
||||
```
|
||||
|
||||
<!--
|
||||
- If you have an alias for kubectl, you can extend shell completion to work with that alias:
|
||||
-->
|
||||
- 如果你为 kubectl 定义了别名,则可以扩展 shell 补全来兼容该别名:
|
||||
|
||||
```bash
|
||||
echo 'alias k=kubectl' >>~/.bash_profile
|
||||
echo 'complete -F __start_kubectl k' >>~/.bash_profile
|
||||
```
|
||||
|
||||
<!--
|
||||
- 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.
|
||||
-->
|
||||
- 如果你是用 Homebrew 安装的 kubectl(如
|
||||
[此页面](/zh/docs/tasks/install-with-homebrew-on-macos/#install-with-homebrew-on-macos)
|
||||
所描述),则kubectl 补全脚本应该已经安装到目录 `/usr/local/etc/bash_completion.d/kubectl`
|
||||
中了。这种情况下,你什么都不需要做。
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
用 Hommbrew 安装的 bash-completion v2 会初始化 目录 `BASH_COMPLETION_COMPAT_DIR`
|
||||
中的所有文件,这就是后两种方法能正常工作的原因。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
In any case, after reloading your shell, kubectl completion should be working.
|
||||
-->
|
||||
总之,重新加载 shell 之后,kubectl 补全功能将立即生效。
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
---
|
||||
title: "fish 自动补全"
|
||||
description: "启用 fish 自动补全的可选配置。"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "fish auto-completion"
|
||||
description: "Optional configuration to enable fish shell auto-completion."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
The kubectl completion script for Fish can be generated with the command `kubectl completion fish`. Sourcing the completion script in your shell enables kubectl autocompletion.
|
||||
|
||||
To do so in all your shell sessions, add the following line to your `~/.config/fish/config.fish` file:
|
||||
-->
|
||||
kubectl 通过命令 `kubectl completion fish` 生成 Fish 自动补全脚本。
|
||||
在 shell 中导入(Sourcing)该自动补全脚本,将启动 kubectl 自动补全功能。
|
||||
|
||||
为了在所有的 shell 会话中实现此功能,请将下面内容加入到文件 `~/.config/fish/config.fish` 中。
|
||||
|
||||
```shell
|
||||
kubectl completion fish | source
|
||||
```
|
||||
|
||||
<!--
|
||||
After reloading your shell, kubectl autocompletion should be working.
|
||||
-->
|
||||
重新加载 shell 后,kubectl 自动补全功能将立即生效。
|
||||
@@ -0,0 +1,44 @@
|
||||
---
|
||||
title: "PowerShell 自动补全"
|
||||
description: "powershell 自动补全的一些可选配置。"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "PowerShell auto-completion"
|
||||
description: "Some optional configuration for powershell auto-completion."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
The kubectl completion script for PowerShell can be generated with the command `kubectl completion powershell`.
|
||||
|
||||
To do so in all your shell sessions, add the following line to your `$PROFILE` file:
|
||||
-->
|
||||
使用命令 `kubectl completion powershell` 生成 PowerShell 的 kubectl 自动补全脚本。
|
||||
|
||||
如果需要自动补全在所有 shell 会话中生效,请将以下命令添加到 `$PROFILE` 文件中:
|
||||
|
||||
```powershell
|
||||
kubectl completion powershell | Out-String | Invoke-Expression
|
||||
```
|
||||
|
||||
<!--
|
||||
This command will regenerate the auto-completion script on every PowerShell start up. You can also add the generated script directly to your `$PROFILE` file.
|
||||
-->
|
||||
此命令将在每次 PowerShell 启动时重新生成自动补全脚本。你还可以将生成的自动补全脚本添加到 `$PROFILE` 文件中。
|
||||
|
||||
<!--
|
||||
To add the generated script to your `$PROFILE` file, run the following line in your powershell prompt:
|
||||
-->
|
||||
如果需要将自动补全脚本直接添加到 `$PROFILE` 文件中,请在 PowerShell 终端运行以下命令:
|
||||
|
||||
```powershell
|
||||
kubectl completion powershell >> $PROFILE
|
||||
```
|
||||
|
||||
<!--
|
||||
After reloading your shell, kubectl autocompletion should be working.
|
||||
-->
|
||||
完成上述操作后重启 shell,kubectl的自动补全就可以工作了。
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
title: "zsh 自动补全"
|
||||
description: "zsh 自动补全的一些可选配置"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "zsh auto-completion"
|
||||
description: "Some optional configuration for zsh auto-completion."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
The kubectl completion script for Zsh can be generated with the command `kubectl completion zsh`. Sourcing the completion script in your shell enables kubectl autocompletion.
|
||||
|
||||
To do so in all your shell sessions, add the following to your `~/.zshrc` file:
|
||||
-->
|
||||
kubectl 通过命令 `kubectl completion zsh` 生成 Zsh 自动补全脚本。
|
||||
在 shell 中导入(Sourcing)该自动补全脚本,将启动 kubectl 自动补全功能。
|
||||
|
||||
为了在所有的 shell 会话中实现此功能,请将下面内容加入到文件 `~/.zshrc` 中。
|
||||
|
||||
```zsh
|
||||
source <(kubectl completion zsh)
|
||||
```
|
||||
|
||||
<!--
|
||||
If you have an alias for kubectl, kubectl autocompletion will automatically work with it.
|
||||
-->
|
||||
如果你为 kubectl 定义了别名,kubectl 自动补全将自动使用它。
|
||||
|
||||
<!--
|
||||
After reloading your shell, kubectl autocompletion should be working.
|
||||
|
||||
If you get an error like `complete:13: command not found: compdef`, then add the following to the beginning of your `~/.zshrc` file:
|
||||
If you get an error like `2: command not found: compdef`, then add the following to the beginning of your `~/.zshrc` file:
|
||||
-->
|
||||
重新加载 shell 后,kubectl 自动补全功能将立即生效。
|
||||
|
||||
如果你收到 `2: command not found: compdef` 这样的错误提示,那请将下面内容添加到 `~/.zshrc` 文件的开头:
|
||||
```zsh
|
||||
autoload -Uz compinit
|
||||
compinit
|
||||
```
|
||||
@@ -0,0 +1,62 @@
|
||||
---
|
||||
title: "验证 kubectl 的安装效果"
|
||||
description: "如何验证 kubectl。"
|
||||
headless: true
|
||||
---
|
||||
<!--
|
||||
---
|
||||
title: "verify kubectl install"
|
||||
description: "How to verify kubectl."
|
||||
headless: true
|
||||
---
|
||||
-->
|
||||
|
||||
<!--
|
||||
In order for kubectl to find and access a Kubernetes cluster, it needs a
|
||||
[kubeconfig file](/docs/concepts/configuration/organize-cluster-access-kubeconfig/),
|
||||
which is created automatically when you create a cluster using
|
||||
[kube-up.sh](https://github.com/kubernetes/kubernetes/blob/master/cluster/kube-up.sh)
|
||||
or successfully deploy a Minikube cluster.
|
||||
By default, kubectl configuration is located at `~/.kube/config`.
|
||||
|
||||
Check that kubectl is properly configured by getting the cluster state:
|
||||
-->
|
||||
为了让 kubectl 能发现并访问 Kubernetes 集群,你需要一个
|
||||
[kubeconfig 文件](/zh/docs/concepts/configuration/organize-cluster-access-kubeconfig/),
|
||||
该文件在
|
||||
[kube-up.sh](https://github.com/kubernetes/kubernetes/blob/master/cluster/kube-up.sh)
|
||||
创建集群时,或成功部署一个 Miniube 集群时,均会自动生成。
|
||||
通常,kubectl 的配置信息存放于文件 `~/.kube/config` 中。
|
||||
|
||||
通过获取集群状态的方法,检查是否已恰当的配置了 kubectl:
|
||||
|
||||
```shell
|
||||
kubectl cluster-info
|
||||
```
|
||||
|
||||
<!--
|
||||
If you see a URL response, kubectl is correctly configured to access your cluster.
|
||||
|
||||
If you see a message similar to the following, kubectl is not configured correctly or is not able to connect to a Kubernetes cluster.
|
||||
-->
|
||||
如果返回一个 URL,则意味着 kubectl 成功的访问到了你的集群。
|
||||
|
||||
如果你看到如下所示的消息,则代表 kubectl 配置出了问题,或无法连接到 Kubernetes 集群。
|
||||
|
||||
```
|
||||
The connection to the server <server-name:port> was refused - did you specify the right host or port?
|
||||
(访问 <server-name:port> 被拒绝 - 你指定的主机和端口是否有误?)
|
||||
```
|
||||
|
||||
<!--
|
||||
For example, if you are intending to run a Kubernetes cluster on your laptop (locally), you will need a tool like Minikube to be installed first and then re-run the commands stated above.
|
||||
|
||||
If kubectl cluster-info returns the url response but you can't access your cluster, to check whether it is configured properly, use:
|
||||
-->
|
||||
例如,如果你想在自己的笔记本上(本地)运行 Kubernetes 集群,你需要先安装一个 Minikube 这样的工具,然后再重新运行上面的命令。
|
||||
|
||||
如果命令 `kubectl cluster-info` 返回了 url,但你还不能访问集群,那可以用以下命令来检查配置是否妥当:
|
||||
|
||||
```shell
|
||||
kubectl cluster-info dump
|
||||
```
|
||||
@@ -0,0 +1,389 @@
|
||||
---
|
||||
title: 在 Linux 系统中安装并设置 kubectl
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: 在 Linux 系统中安装 kubectl
|
||||
---
|
||||
<!--
|
||||
reviewers:
|
||||
- mikedanese
|
||||
title: Install and Set Up kubectl on Linux
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: Install kubectl on Linux
|
||||
-->
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
<!--
|
||||
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.
|
||||
Using the latest compatible version of kubectl helps avoid unforeseen issues.
|
||||
-->
|
||||
kubectl 版本和集群版本之间的差异必须在一个小版本号内。
|
||||
例如:v{{< skew currentVersion >}} 版本的客户端能与 v{{< skew currentVersionAddMinor -1 >}}、
|
||||
v{{< skew currentVersionAddMinor 0 >}} 和 v{{< skew currentVersionAddMinor 1 >}} 版本的控制面通信。
|
||||
用最新兼容版的 kubectl 有助于避免不可预见的问题。
|
||||
|
||||
<!--
|
||||
## Install kubectl on Linux
|
||||
-->
|
||||
## 在 Linux 系统中安装 kubectl {#install-kubectl-on-linux}
|
||||
|
||||
<!--
|
||||
The following methods exist for installing kubectl on Linux:
|
||||
-->
|
||||
在 Linux 系统中安装 kubectl 有如下几种方法:
|
||||
|
||||
<!--
|
||||
- [Install kubectl binary with curl on Linux](#install-kubectl-binary-with-curl-on-linux)
|
||||
- [Install using native package management](#install-using-native-package-management)
|
||||
- [Install using other package management](#install-using-other-package-management)
|
||||
-->
|
||||
- [用 curl 在 Linux 系统中安装 kubectl](#install-kubectl-binary-with-curl-on-linux)
|
||||
- [用原生包管理工具安装](#install-using-native-package-management)
|
||||
- [用其他包管理工具安装](#install-using-other-package-management)
|
||||
|
||||
<!--
|
||||
### Install kubectl binary with curl on Linux
|
||||
-->
|
||||
### 用 curl 在 Linux 系统中安装 kubectl {#install-kubectl-binary-with-curl-on-linux}
|
||||
|
||||
<!--
|
||||
1. Download the latest release with the command:
|
||||
-->
|
||||
1. 用以下命令下载最新发行版:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
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.
|
||||
|
||||
For example, to download version {{< param "fullversion" >}} on Linux, type:
|
||||
-->
|
||||
如需下载某个指定的版本,请用指定版本号替换该命令的这一部分:
|
||||
`$(curl -L -s https://dl.k8s.io/release/stable.txt)`。
|
||||
|
||||
例如,要在 Linux 中下载 {{< param "fullversion" >}} 版本,请输入:
|
||||
|
||||
```bash
|
||||
curl -LO https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/linux/amd64/kubectl
|
||||
```
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Validate the binary (optional)
|
||||
|
||||
Download the kubectl checksum file:
|
||||
-->
|
||||
2. 验证该可执行文件(可选步骤)
|
||||
|
||||
下载 kubectl 校验和文件:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
|
||||
```
|
||||
|
||||
<!--
|
||||
Validate the kubectl binary against the checksum file:
|
||||
-->
|
||||
基于校验和文件,验证 kubectl 的可执行文件:
|
||||
|
||||
```bash
|
||||
echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
|
||||
```
|
||||
|
||||
<!--
|
||||
If valid, the output is:
|
||||
-->
|
||||
验证通过时,输出为:
|
||||
|
||||
```console
|
||||
kubectl: OK
|
||||
```
|
||||
|
||||
<!--
|
||||
If the check fails, `sha256` exits with nonzero status and prints output similar to:
|
||||
-->
|
||||
验证失败时,`sha256` 将以非零值退出,并打印如下输出:
|
||||
|
||||
```bash
|
||||
kubectl: FAILED
|
||||
sha256sum: WARNING: 1 computed checksum did NOT match
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Download the same version of the binary and checksum.
|
||||
-->
|
||||
下载的 kubectl 与校验和文件版本必须相同。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Install kubectl
|
||||
-->
|
||||
3. 安装 kubectl
|
||||
|
||||
```bash
|
||||
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
If you do not have root access on the target system, you can still install kubectl to the `~/.local/bin` directory:
|
||||
-->
|
||||
即使你没有目标系统的 root 权限,仍然可以将 kubectl 安装到目录 `~/.local/bin` 中:
|
||||
|
||||
```bash
|
||||
chmod +x kubectl
|
||||
mkdir -p ~/.local/bin
|
||||
mv ./kubectl ~/.local/bin/kubectl
|
||||
# 之后将 ~/.local/bin 附加(或前置)到 $PATH
|
||||
```
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Test to ensure the version you installed is up-to-date:
|
||||
Or use this for detailed view of version:
|
||||
-->
|
||||
4. 执行测试,以保障你安装的版本是最新的:
|
||||
|
||||
```bash
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
或者使用如下命令来查看版本的详细信息:
|
||||
```cmd
|
||||
kubectl version --client --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
### Install using native package management
|
||||
-->
|
||||
### 用原生包管理工具安装 {#install-using-native-package-management}
|
||||
|
||||
{{< tabs name="kubectl_install" >}}
|
||||
{{% tab name="Ubuntu、Debian 或 HypriotOS" %}}
|
||||
|
||||
<!--
|
||||
1. Update the `apt` package index and install packages needed to use the Kubernetes `apt` repository:
|
||||
-->
|
||||
1. 更新 `apt` 包索引,并安装使用 Kubernetes `apt` 仓库所需要的包:
|
||||
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y apt-transport-https ca-certificates curl
|
||||
```
|
||||
<!--
|
||||
2. Download the Google Cloud public signing key:
|
||||
-->
|
||||
2. 下载 Google Cloud 公开签名秘钥:
|
||||
|
||||
```shell
|
||||
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
||||
```
|
||||
|
||||
<!--
|
||||
3. Add the Kubernetes `apt` repository:
|
||||
-->
|
||||
3. 添加 Kubernetes `apt` 仓库:
|
||||
|
||||
```shell
|
||||
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
|
||||
```
|
||||
|
||||
<!--
|
||||
4. Update `apt` package index with the new repository and install kubectl:
|
||||
-->
|
||||
4. 更新 `apt` 包索引,使之包含新的仓库并安装 kubectl:
|
||||
|
||||
```shell
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y kubectl
|
||||
```
|
||||
{{% /tab %}}
|
||||
|
||||
{{% tab name="基于 Red Hat 的发行版" %}}
|
||||
|
||||
```shell
|
||||
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
|
||||
[kubernetes]
|
||||
name=Kubernetes
|
||||
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
repo_gpgcheck=1
|
||||
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
|
||||
EOF
|
||||
sudo yum install -y kubectl
|
||||
```
|
||||
|
||||
{{% /tab %}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
### Install using other package management
|
||||
-->
|
||||
### 用其他包管理工具安装 {#install-using-other-package-management}
|
||||
|
||||
{{< tabs name="other_kubectl_install" >}}
|
||||
{{% tab name="Snap" %}}
|
||||
<!--
|
||||
If you are on Ubuntu or another Linux distribution that supports the [snap](https://snapcraft.io/docs/core/install) package manager, kubectl is available as a [snap](https://snapcraft.io/) application.
|
||||
-->
|
||||
如果你使用的 Ubuntu 或其他 Linux 发行版,内建支持
|
||||
[snap](https://snapcraft.io/docs/core/install) 包管理工具,
|
||||
则可用 [snap](https://snapcraft.io/) 命令安装 kubectl。
|
||||
|
||||
```shell
|
||||
snap install kubectl --classic
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
{{% /tab %}}
|
||||
|
||||
{{% tab name="Homebrew" %}}
|
||||
<!--
|
||||
If you are on Linux and using [Homebrew](https://docs.brew.sh/Homebrew-on-Linux) package manager, kubectl is available for [installation](https://docs.brew.sh/Homebrew-on-Linux#install).
|
||||
-->
|
||||
如果你使用 Linux 系统,并且装了 [Homebrew](https://docs.brew.sh/Homebrew-on-Linux)
|
||||
包管理工具,
|
||||
则可以使用这种方式[安装](https://docs.brew.sh/Homebrew-on-Linux#install) kubectl。
|
||||
|
||||
```shell
|
||||
brew install kubectl
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
{{% /tab %}}
|
||||
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
## Verify kubectl configuration
|
||||
-->
|
||||
## 验证 kubectl 配置 {#verify-kubectl-configration}
|
||||
|
||||
{{< include "included/verify-kubectl.md" >}}
|
||||
|
||||
<!--
|
||||
## Optional kubectl configurations and plugins
|
||||
|
||||
### Enable shell autocompletion
|
||||
-->
|
||||
## kubectl 的可选配置和插件 {#optional-kubectl-configurations}
|
||||
|
||||
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
|
||||
|
||||
<!--
|
||||
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell, which can save you a lot of typing.
|
||||
|
||||
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
|
||||
-->
|
||||
kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以为你节省大量的输入。
|
||||
|
||||
下面是为 Bash、Fish 和 Zsh 设置自动补全功能的操作步骤。
|
||||
|
||||
{{< tabs name="kubectl_autocompletion" >}}
|
||||
{{< tab name="Bash" include="included/optional-kubectl-configs-bash-linux.md" />}}
|
||||
{{< tab name="Fish" include="included/optional-kubectl-configs-fish.md" />}}
|
||||
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
### Install `kubectl convert` plugin
|
||||
-->
|
||||
### 安装 `kubectl convert` 插件
|
||||
|
||||
{{< include "included/kubectl-convert-overview.md" >}}
|
||||
|
||||
<!--
|
||||
1. Download the latest release with the command:
|
||||
-->
|
||||
1. 用以下命令下载最新发行版:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert"
|
||||
```
|
||||
<!--
|
||||
2. Validate the binary (optional)
|
||||
|
||||
Download the kubectl-convert checksum file:
|
||||
-->
|
||||
2. 验证该可执行文件(可选步骤)
|
||||
|
||||
下载 kubectl-convert 校验和文件:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert.sha256"
|
||||
```
|
||||
|
||||
<!--
|
||||
Validate the kubectl-convert binary against the checksum file:
|
||||
-->
|
||||
基于校验和,验证 kubectl-convert 的可执行文件:
|
||||
|
||||
```bash
|
||||
echo "$(cat kubectl-convert.sha256) kubectl-convert" | sha256sum --check
|
||||
```
|
||||
|
||||
<!--
|
||||
If valid, the output is:
|
||||
-->
|
||||
验证通过时,输出为:
|
||||
|
||||
```console
|
||||
kubectl-convert: OK
|
||||
```
|
||||
|
||||
<!--
|
||||
If the check fails, `sha256` exits with nonzero status and prints output similar to:
|
||||
-->
|
||||
验证失败时,`sha256` 将以非零值退出,并打印输出类似于:
|
||||
|
||||
```bash
|
||||
kubectl-convert: FAILED
|
||||
sha256sum: WARNING: 1 computed checksum did NOT match
|
||||
```
|
||||
{{< note >}}
|
||||
<!--
|
||||
Download the same version of the binary and checksum.
|
||||
-->
|
||||
下载相同版本的可执行文件和校验和。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
3. Install kubectl-convert
|
||||
-->
|
||||
3. 安装 kubectl-convert
|
||||
|
||||
```bash
|
||||
sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
|
||||
```
|
||||
|
||||
<!--
|
||||
4. Verify plugin is successfully installed
|
||||
-->
|
||||
4. 验证插件是否安装成功
|
||||
|
||||
```shell
|
||||
kubectl convert --help
|
||||
```
|
||||
|
||||
<!--
|
||||
If you do not see an error, it means the plugin is successfully installed.
|
||||
-->
|
||||
如果你没有看到任何错误就代表插件安装成功了。
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
{{< include "included/kubectl-whats-next.md" >}}
|
||||
|
||||
@@ -0,0 +1,405 @@
|
||||
---
|
||||
title: 在 macOS 系统上安装和设置 kubectl
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: 在 macOS 系统上安装 kubectl
|
||||
---
|
||||
<!--
|
||||
reviewers:
|
||||
- mikedanese
|
||||
title: Install and Set Up kubectl on macOS
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: Install kubectl on macOS
|
||||
-->
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
<!--
|
||||
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.
|
||||
Using the latest compatible version of kubectl helps avoid unforeseen issues.
|
||||
-->
|
||||
kubectl 版本和集群之间的差异必须在一个小版本号之内。
|
||||
例如:v{{< skew currentVersion >}} 版本的客户端能与 v{{< skew currentVersionAddMinor -1 >}}、
|
||||
v{{< skew currentVersionAddMinor 0 >}} 和 v{{< skew currentVersionAddMinor 1 >}} 版本的控制面通信。
|
||||
用最新兼容版本的 kubectl 有助于避免不可预见的问题。
|
||||
|
||||
<!--
|
||||
## Install kubectl on macOS
|
||||
-->
|
||||
## 在 macOS 系统上安装 kubectl {#install-kubectl-on-macos}
|
||||
|
||||
<!--
|
||||
The following methods exist for installing kubectl on macOS:
|
||||
-->
|
||||
在 macOS 系统上安装 kubectl 有如下方法:
|
||||
|
||||
<!--
|
||||
- [Install kubectl binary with curl on macOS](#install-kubectl-binary-with-curl-on-macos)
|
||||
- [Install with Homebrew on macOS](#install-with-homebrew-on-macos)
|
||||
- [Install with Macports on macOS](#install-with-macports-on-macos)
|
||||
- [Install on macOS as part of the Google Cloud SDK](#install-on-macos-as-part-of-the-google-cloud-sdk)
|
||||
-->
|
||||
- [用 curl 在 macOS 系统上安装 kubectl](#install-kubectl-binary-with-curl-on-macos)
|
||||
- [用 Homebrew 在 macOS 系统上安装](#install-with-homebrew-on-macos)
|
||||
- [用 Macports 在 macOS 上安装](#install-with-macports-on-macos)
|
||||
- [作为谷歌云 SDK 的一部分,在 macOS 上安装](#install-on-macos-as-part-of-the-google-cloud-sdk)
|
||||
|
||||
<!--
|
||||
### Install kubectl binary with curl on macOS {#install-kubectl-binary-with-curl-on-macos}
|
||||
-->
|
||||
### 用 curl 在 macOS 系统上安装 kubectl {#install-kubectl-binary-with-curl-on-macos}
|
||||
|
||||
<!--
|
||||
1. Download the latest release:
|
||||
-->
|
||||
1. 下载最新的发行版:
|
||||
|
||||
{{< tabs name="download_binary_macos" >}}
|
||||
{{< tab name="Intel" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"
|
||||
{{< /tab >}}
|
||||
{{< tab name="Apple Silicon" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl"
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
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.
|
||||
|
||||
For example, to download version {{< param "fullversion" >}} on Intel macOS, type:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/arm64/kubectl"
|
||||
```
|
||||
|
||||
-->
|
||||
如果需要下载某个指定的版本,用该指定版本号替换掉命令的这个部分:`$(curl -L -s https://dl.k8s.io/release/stable.txt)`。
|
||||
例如:要为 Intel macOS 系统下载 {{< param "fullversion" >}} 版本,则输入:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/amd64/kubectl"
|
||||
```
|
||||
|
||||
<!--
|
||||
And for macOS on Apple Silicon, type:
|
||||
-->
|
||||
对于 Apple Silicon 版本的 macOS,输入:
|
||||
|
||||
```bash
|
||||
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/darwin/arm64/kubectl"
|
||||
```
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Validate the binary (optional)
|
||||
|
||||
Download the kubectl checksum file:
|
||||
-->
|
||||
2. 验证可执行文件(可选操作)
|
||||
|
||||
下载 kubectl 的校验和文件:
|
||||
|
||||
{{< tabs name="download_checksum_macos" >}}
|
||||
{{< tab name="Intel" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256"
|
||||
{{< /tab >}}
|
||||
{{< tab name="Apple Silicon" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl.sha256"
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
Validate the kubectl binary against the checksum file:
|
||||
-->
|
||||
根据校验和文件,验证 kubectl:
|
||||
|
||||
```bash
|
||||
echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check
|
||||
```
|
||||
<!--
|
||||
If valid, the output is:
|
||||
-->
|
||||
验证通过时,输出如下:
|
||||
|
||||
```console
|
||||
kubectl: OK
|
||||
```
|
||||
|
||||
<!--
|
||||
If the check fails, `shasum` exits with nonzero status and prints output similar to:
|
||||
-->
|
||||
验证失败时,`shasum` 将以非零值退出,并打印如下输出:
|
||||
|
||||
```
|
||||
kubectl: FAILED
|
||||
shasum: WARNING: 1 computed checksum did NOT match
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Download the same version of the binary and checksum.
|
||||
-->
|
||||
下载的 kubectl 与校验和文件版本要相同。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Make the kubectl binary executable.
|
||||
-->
|
||||
3. 将 kubectl 置为可执行文件:
|
||||
|
||||
```bash
|
||||
chmod +x ./kubectl
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Move the kubectl binary to a file location on your system `PATH`.
|
||||
-->
|
||||
4. 将可执行文件 kubectl 移动到系统可寻址路径 `PATH` 内的一个位置:
|
||||
|
||||
```bash
|
||||
sudo mv ./kubectl /usr/local/bin/kubectl
|
||||
sudo chown root: /usr/local/bin/kubectl
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Make sure `/usr/local/bin` is in your PATH environment variable.
|
||||
-->
|
||||
确保 `/usr/local/bin` 在你的 PATH 环境变量中。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Test to ensure the version you installed is up-to-date:
|
||||
Or use this for detailed view of version:
|
||||
-->
|
||||
5. 测试一下,确保你安装的是最新的版本:
|
||||
|
||||
```bash
|
||||
kubectl version --client
|
||||
```
|
||||
或者使用下面命令来查看版本的详细信息:
|
||||
```cmd
|
||||
kubectl version --client --output=yaml
|
||||
```
|
||||
|
||||
<!--
|
||||
### Install with Homebrew on macOS {#install-with-homebrew-on-macos}
|
||||
-->
|
||||
### 用 Homebrew 在 macOS 系统上安装 {#install-with-homebrew-on-macos}
|
||||
|
||||
<!--
|
||||
If you are on macOS and using [Homebrew](https://brew.sh/) package manager, you can install kubectl with Homebrew.
|
||||
-->
|
||||
如果你是 macOS 系统,且用的是 [Homebrew](https://brew.sh/) 包管理工具,
|
||||
则可以用 Homebrew 安装 kubectl。
|
||||
|
||||
<!--
|
||||
1. Run the installation command:
|
||||
-->
|
||||
1. 运行安装命令:
|
||||
|
||||
```bash
|
||||
brew install kubectl
|
||||
```
|
||||
|
||||
或
|
||||
|
||||
```bash
|
||||
brew install kubernetes-cli
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Test to ensure the version you installed is up-to-date:
|
||||
-->
|
||||
2. 测试一下,确保你安装的是最新的版本:
|
||||
|
||||
```bash
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
<!--
|
||||
### Install with Macports on macOS {#install-with-macports-on-macos}
|
||||
-->
|
||||
### 用 Macports 在 macOS 上安装 {#install-with-macports-on-macos}
|
||||
|
||||
<!--
|
||||
If you are on macOS and using [Macports](https://macports.org/) package manager, you can install kubectl with Macports.
|
||||
-->
|
||||
如果你用的是 macOS,且用 [Macports](https://macports.org/) 包管理工具,则你可以用 Macports 安装kubectl。
|
||||
|
||||
<!--
|
||||
1. Run the installation command:
|
||||
-->
|
||||
1. 运行安装命令:
|
||||
|
||||
```bash
|
||||
sudo port selfupdate
|
||||
sudo port install kubectl
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Test to ensure the version you installed is up-to-date:
|
||||
-->
|
||||
2. 测试一下,确保你安装的是最新的版本:
|
||||
|
||||
```bash
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
<!--
|
||||
## Verify kubectl configuration {#verify-kubectl-configuration}
|
||||
-->
|
||||
## 验证 kubectl 配置 {#verify-kubectl-configuration}
|
||||
|
||||
{{< include "included/verify-kubectl.md" >}}
|
||||
|
||||
<!--
|
||||
## Optional kubectl configurations and plugins {#optional-kubectl-configurations}
|
||||
|
||||
### Enable shell autocompletion {#enable-shell-autocompletion}
|
||||
-->
|
||||
## 可选的 kubectl 配置和插件 {#optional-kubectl-configurations-and-plugins}
|
||||
|
||||
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
|
||||
|
||||
<!--
|
||||
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell which can save you a lot of typing.
|
||||
|
||||
Below are the procedures to set up autocompletion for Bash, Fish, and Zsh.
|
||||
-->
|
||||
kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以为你节省大量的输入。
|
||||
|
||||
下面是为 Bash、Fish 和 Zsh 设置自动补全功能的操作步骤。
|
||||
|
||||
{{< tabs name="kubectl_autocompletion" >}}
|
||||
{{< tab name="Bash" include="included/optional-kubectl-configs-bash-mac.md" />}}
|
||||
{{< tab name="Fish" include="included/optional-kubectl-configs-fish.md" />}}
|
||||
{{< tab name="Zsh" include="included/optional-kubectl-configs-zsh.md" />}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
### Install `kubectl convert` plugin
|
||||
-->
|
||||
### 安装 `kubectl convert` 插件
|
||||
|
||||
{{< include "included/kubectl-convert-overview.md" >}}
|
||||
|
||||
<!--
|
||||
1. Download the latest release with the command:
|
||||
-->
|
||||
1. 用以下命令下载最新发行版:
|
||||
|
||||
{{< tabs name="download_convert_binary_macos" >}}
|
||||
{{< tab name="Intel" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert"
|
||||
{{< /tab >}}
|
||||
{{< tab name="Apple Silicon" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert"
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
1. Validate the binary (optional)
|
||||
|
||||
Download the kubectl-convert checksum file:
|
||||
-->
|
||||
1. 验证该可执行文件(可选步骤)
|
||||
|
||||
下载 kubectl-convert 校验和文件:
|
||||
|
||||
{{< tabs name="download_convert_checksum_macos" >}}
|
||||
{{< tab name="Intel" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl-convert.sha256"
|
||||
{{< /tab >}}
|
||||
{{< tab name="Apple Silicon" codelang="bash" >}}
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl-convert.sha256"
|
||||
{{< /tab >}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
Validate the kubectl-convert binary against the checksum file:
|
||||
-->
|
||||
基于校验和,验证 kubectl-convert 的可执行文件:
|
||||
|
||||
```bash
|
||||
echo "$(cat kubectl-convert.sha256) kubectl-convert" | shasum -a 256 --check
|
||||
```
|
||||
|
||||
<!--
|
||||
If valid, the output is:
|
||||
-->
|
||||
验证通过时,输出为:
|
||||
|
||||
```console
|
||||
kubectl-convert: OK
|
||||
```
|
||||
|
||||
<!--
|
||||
If the check fails, `shasum` exits with nonzero status and prints output similar to:
|
||||
-->
|
||||
验证失败时,`sha256` 将以非零值退出,并打印输出类似于:
|
||||
|
||||
```bash
|
||||
kubectl-convert: FAILED
|
||||
shasum: WARNING: 1 computed checksum did NOT match
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Download the same version of the binary and checksum.
|
||||
-->
|
||||
下载相同版本的可执行文件和校验和。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Make kubectl-convert binary executable
|
||||
-->
|
||||
1. 使 kubectl-convert 二进制文件可执行
|
||||
|
||||
```bash
|
||||
chmod +x ./kubectl-convert
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Move the kubectl-convert binary to a file location on your system `PATH`.
|
||||
-->
|
||||
1. 将 kubectl-convert 可执行文件移动到系统 `PATH` 环境变量中的一个位置。
|
||||
|
||||
```bash
|
||||
sudo mv ./kubectl-convert /usr/local/bin/kubectl-convert
|
||||
sudo chown root: /usr/local/bin/kubectl-convert
|
||||
```
|
||||
|
||||
{{< note >}}
|
||||
<!--
|
||||
Make sure `/usr/local/bin` is in your PATH environment variable.
|
||||
-->
|
||||
确保你的 PATH 环境变量中存在 `/usr/local/bin`
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Verify plugin is successfully installed
|
||||
-->
|
||||
1. 验证插件是否安装成功
|
||||
|
||||
```shell
|
||||
kubectl convert --help
|
||||
```
|
||||
|
||||
<!--
|
||||
If you do not see an error, it means the plugin is successfully installed.
|
||||
-->
|
||||
如果你没有看到任何错误就代表插件安装成功了。
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
{{< include "included/kubectl-whats-next.md" >}}
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
---
|
||||
title: 在 Windows 上安装 kubectl
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: Windows 安装 kubectl
|
||||
---
|
||||
<!--
|
||||
reviewers:
|
||||
- mikedanese
|
||||
title: Install and Set Up kubectl on Windows
|
||||
content_type: task
|
||||
weight: 10
|
||||
card:
|
||||
name: tasks
|
||||
weight: 20
|
||||
title: Install kubectl on Windows
|
||||
-->
|
||||
|
||||
## {{% heading "prerequisites" %}}
|
||||
|
||||
<!--
|
||||
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.
|
||||
Using the latest compatible version of kubectl helps avoid unforeseen issues.
|
||||
-->
|
||||
kubectl 版本和集群版本之间的差异必须在一个小版本号内。
|
||||
例如:v{{< skew currentVersion >}} 版本的客户端能与 v{{< skew currentVersionAddMinor -1 >}}、
|
||||
v{{< skew currentVersionAddMinor 0 >}} 和 v{{< skew currentVersionAddMinor 1 >}} 版本的控制面通信。
|
||||
用最新兼容版的 kubectl 有助于避免不可预见的问题。
|
||||
|
||||
<!--
|
||||
## Install kubectl on Windows
|
||||
-->
|
||||
## 在 Windows 上安装 kubectl {#install-kubectl-on-windows}
|
||||
|
||||
<!--
|
||||
The following methods exist for installing kubectl on Windows:
|
||||
-->
|
||||
在 Windows 系统中安装 kubectl 有如下几种方法:
|
||||
|
||||
- [用 curl 在 Windows 上安装 kubectl](#install-kubectl-binary-with-curl-on-windows)
|
||||
- [在 Windows 上用 Chocolatey 或 Scoop 安装](#install-on-windows-using-chocolatey-or-scoop)
|
||||
|
||||
<!--
|
||||
### Install kubectl binary with curl on Windows
|
||||
-->
|
||||
### 用 curl 在 Windows 上安装 kubectl {#install-kubectl-binary-with-curl-on-windows}
|
||||
|
||||
<!--
|
||||
1. Download the [latest release {{< param "fullversion" >}}](https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe).
|
||||
|
||||
Or if you have `curl` installed, use this command:
|
||||
-->
|
||||
1. 下载 [最新发行版 {{< param "fullversion" >}}](https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe)。
|
||||
|
||||
如果你已安装了 `curl`,也可以使用此命令:
|
||||
|
||||
```powershell
|
||||
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe"
|
||||
```
|
||||
|
||||
<!--
|
||||
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).
|
||||
-->
|
||||
{{< note >}}
|
||||
要想找到最新稳定的版本(例如:为了编写脚本),可以看看这里 [https://dl.k8s.io/release/stable.txt](https://dl.k8s.io/release/stable.txt)。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
1. Validate the binary (optional)
|
||||
|
||||
Download the `kubectl` checksum file:
|
||||
-->
|
||||
1. 验证该可执行文件(可选步骤)
|
||||
|
||||
下载 `kubectl` 校验和文件:
|
||||
|
||||
```powershell
|
||||
curl -LO "https://dl.k8s.io/{{< param "fullversion" >}}/bin/windows/amd64/kubectl.exe.sha256"
|
||||
```
|
||||
|
||||
<!--
|
||||
Validate the `kubectl` binary against the checksum file:
|
||||
-->
|
||||
基于校验和文件,验证 `kubectl` 的可执行文件:
|
||||
|
||||
<!--
|
||||
- Using Command Prompt to manually compare `CertUtil`'s output to the checksum file downloaded:
|
||||
-->
|
||||
- 在命令行环境中,手工对比 `CertUtil` 命令的输出与校验和文件:
|
||||
|
||||
```cmd
|
||||
CertUtil -hashfile kubectl.exe SHA256
|
||||
type kubectl.exe.sha256
|
||||
```
|
||||
|
||||
<!--
|
||||
- Using PowerShell to automate the verification using the `-eq` operator to get a `True` or `False` result:
|
||||
-->
|
||||
- 用 PowerShell 自动验证,用运算符 `-eq` 来直接取得 `True` 或 `False` 的结果:
|
||||
|
||||
```powershell
|
||||
$($(CertUtil -hashfile .\kubectl.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl.exe.sha256)
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Append or prepend the `kubectl` binary folder to your `PATH` environment variable.
|
||||
|
||||
1. Test to ensure the version of `kubectl` is the same as downloaded:
|
||||
Or use this for detailed view of version:
|
||||
-->
|
||||
1. 将 `kubectl` 二进制文件夹追加或插入到你的 `PATH` 环境变量中。
|
||||
|
||||
1. 测试一下,确保此 `kubectl` 的版本和期望版本一致:
|
||||
|
||||
```cmd
|
||||
kubectl version --client
|
||||
```
|
||||
或者使用下面命令来查看版本的详细信息:
|
||||
```cmd
|
||||
kubectl version --client --output=yaml
|
||||
```
|
||||
|
||||
|
||||
<!--
|
||||
[Docker Desktop for Windows](https://docs.docker.com/docker-for-windows/#kubernetes) adds its own version of `kubectl` to `PATH`.
|
||||
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`.
|
||||
-->
|
||||
{{< note >}}
|
||||
[Windows 版的 Docker Desktop](https://docs.docker.com/docker-for-windows/#kubernetes)
|
||||
将其自带版本的 `kubectl` 添加到 `PATH`。
|
||||
如果你之前安装过 Docker Desktop,可能需要把此 `PATH` 条目置于 Docker Desktop 安装的条目之前,
|
||||
或者直接删掉 Docker Desktop 的 `kubectl`。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
### Install on Windows using Chocolatey or Scoop
|
||||
-->
|
||||
### 在 Windows 上用 Chocolatey 或 Scoop 安装 {#install-on-windows-using-chocolatey-or-scoop}
|
||||
|
||||
<!--
|
||||
1. To install kubectl on Windows you can use either [Chocolatey](https://chocolatey.org) package manager or [Scoop](https://scoop.sh) command-line installer.
|
||||
-->
|
||||
1. 要在 Windows 上安装 kubectl,你可以使用包管理器 [Chocolatey](https://chocolatey.org)
|
||||
或是命令行安装器 [Scoop](https://scoop.sh)。
|
||||
|
||||
{{< tabs name="kubectl_win_install" >}}
|
||||
{{% tab name="choco" %}}
|
||||
```powershell
|
||||
choco install kubernetes-cli
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{% tab name="scoop" %}}
|
||||
```powershell
|
||||
scoop install kubectl
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{< /tabs >}}
|
||||
|
||||
<!--
|
||||
1. Test to ensure the version you installed is up-to-date:
|
||||
-->
|
||||
2. 测试一下,确保安装的是最新版本:
|
||||
|
||||
```powershell
|
||||
kubectl version --client
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Navigate to your home directory:
|
||||
-->
|
||||
3. 导航到你的 home 目录:
|
||||
|
||||
<!--
|
||||
# If you're using cmd.exe, run: cd %USERPROFILE%
|
||||
-->
|
||||
```powershell
|
||||
# 当你用 cmd.exe 时,则运行: cd %USERPROFILE%
|
||||
cd ~
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Create the `.kube` directory:
|
||||
-->
|
||||
4. 创建目录 `.kube`:
|
||||
|
||||
```powershell
|
||||
mkdir .kube
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Change to the `.kube` directory you just created:
|
||||
-->
|
||||
5. 切换到新创建的目录 `.kube`
|
||||
|
||||
```powershell
|
||||
cd .kube
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Configure kubectl to use a remote Kubernetes cluster:
|
||||
-->
|
||||
6. 配置 kubectl,以接入远程的 Kubernetes 集群:
|
||||
|
||||
```powershell
|
||||
New-Item config -type file
|
||||
```
|
||||
|
||||
<!--
|
||||
Edit the config file with a text editor of your choice, such as Notepad.
|
||||
-->
|
||||
{{< note >}}
|
||||
编辑配置文件,你需要先选择一个文本编辑器,比如 Notepad。
|
||||
{{< /note >}}
|
||||
|
||||
<!--
|
||||
## Verify kubectl configuration
|
||||
-->
|
||||
## 验证 kubectl 配置 {#verify-kubectl-configration}
|
||||
|
||||
{{< include "included/verify-kubectl.md" >}}
|
||||
|
||||
<!--
|
||||
## Optional kubectl configurations and plugins
|
||||
|
||||
### Enable shell autocompletion
|
||||
-->
|
||||
## kubectl 可选配置和插件 {#optional-kubectl-configurations}
|
||||
|
||||
### 启用 shell 自动补全功能 {#enable-shell-autocompletion}
|
||||
|
||||
<!--
|
||||
kubectl provides autocompletion support for Bash, Zsh, Fish, and PowerShell, which can save you a lot of typing.
|
||||
|
||||
Below are the procedures to set up autocompletion for PowerShell.
|
||||
-->
|
||||
kubectl 为 Bash、Zsh、Fish 和 PowerShell 提供自动补全功能,可以为你节省大量的输入。
|
||||
|
||||
下面是设置 PowerShell 自动补全功能的操作步骤。
|
||||
|
||||
{{< include "included/optional-kubectl-configs-pwsh.md" >}}
|
||||
|
||||
<!--
|
||||
### Install `kubectl convert` plugin
|
||||
-->
|
||||
### 安装 `kubectl convert` 插件
|
||||
|
||||
{{< include "included/kubectl-convert-overview.md" >}}
|
||||
|
||||
<!--
|
||||
1. Download the latest release with the command:
|
||||
-->
|
||||
1. 用以下命令下载最新发行版:
|
||||
|
||||
```powershell
|
||||
curl -LO "https://dl.k8s.io/release/{{< param "fullversion" >}}/bin/windows/amd64/kubectl-convert.exe"
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Validate the binary (optional)
|
||||
|
||||
Download the `kubectl-convert` checksum file:
|
||||
-->
|
||||
1. 验证该可执行文件(可选步骤)
|
||||
|
||||
下载 `kubectl-convert` 校验和文件:
|
||||
|
||||
```powershell
|
||||
curl -LO "https://dl.k8s.io/{{< param "fullversion" >}}/bin/windows/amd64/kubectl-convert.exe.sha256"
|
||||
```
|
||||
|
||||
<!--
|
||||
Validate the `kubectl-convert` binary against the checksum file:
|
||||
|
||||
- Using Command Prompt to manually compare `CertUtil`'s output to the checksum file downloaded:
|
||||
-->
|
||||
基于校验和,验证 `kubectl-convert` 的可执行文件:
|
||||
|
||||
- 用提示的命令对 `CertUtil` 的输出和下载的校验和文件进行手动比较。
|
||||
|
||||
```cmd
|
||||
CertUtil -hashfile kubectl-convert.exe SHA256
|
||||
type kubectl-convert.exe.sha256
|
||||
```
|
||||
|
||||
<!--
|
||||
- Using PowerShell to automate the verification using the `-eq` operator to get a `True` or `False` result:
|
||||
-->
|
||||
- 使用 PowerShell `-eq` 操作使验证自动化,获得 `True` 或者 `False` 的结果:
|
||||
|
||||
```powershell
|
||||
$($(CertUtil -hashfile .\kubectl-convert.exe SHA256)[1] -replace " ", "") -eq $(type .\kubectl-convert.exe.sha256)
|
||||
```
|
||||
|
||||
<!--
|
||||
1. Append or prepend the `kubectl-convert` binary folder to your `PATH` environment variable.
|
||||
|
||||
1. Verify plugin is successfully installed
|
||||
-->
|
||||
1. 将 `kubectl-convert` 二进制文件夹附加或添加到你的 `PATH` 环境变量中。
|
||||
|
||||
1. 验证插件是否安装成功
|
||||
|
||||
```shell
|
||||
kubectl convert --help
|
||||
```
|
||||
|
||||
<!--
|
||||
If you do not see an error, it means the plugin is successfully installed.
|
||||
-->
|
||||
如果你没有看到任何错误就代表插件安装成功了。
|
||||
|
||||
## {{% heading "whatsnext" %}}
|
||||
|
||||
{{< include "included/kubectl-whats-next.md" >}}
|
||||
Reference in New Issue
Block a user