# 在 Linux 系统中安装并设置 kubectl

LLMS index: [llms.txt](/llms.txt)

---

<!-- 
reviewers:
- mikedanese
title: Install and Set Up kubectl on Linux
content_type: task
weight: 10
-->

## 准备开始

<!--
You must use a kubectl version that is within one minor version difference of
your cluster. For example, a v1.36 client can communicate
with v1.35, v1.36,
and v1.37 control planes.
Using the latest compatible version of kubectl helps avoid unforeseen issues.
-->
kubectl 版本和集群版本之间的差异必须在一个小版本号内。
例如：v1.36 版本的客户端能与 v1.35、
v1.36 和 v1.37 版本的控制面通信。
用最新兼容版的 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. 用以下命令下载最新发行版：

   <ul class="nav nav-tabs" id="tabs-download-binary-linux" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-download-binary-linux-0" role="tab" aria-controls="tabs-download-binary-linux-0" aria-selected="true">x86-64</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-download-binary-linux-1" role="tab" aria-controls="tabs-download-binary-linux-1">ARM64</a></li></ul>

<div class="tab-content" id="tabs-download-binary-linux-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-download-binary-linux-0" role="tabpanel" aria-labelledby="tabs-download-binary-linux-0-tab" tabindex="download-binary-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/amd64/kubectl&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-download-binary-linux-1" role="tabpanel" aria-labelledby="tabs-download-binary-linux-1-tab" tabindex="download-binary-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/arm64/kubectl&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div></div>


   
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4>   <!--
   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 1.36.0 on Linux x86-64, type:
   -->
<p>如需下载某个指定的版本，请用指定版本号替换该命令的这一部分：
<code>$(curl -L -s https://dl.k8s.io/release/stable.txt)</code>。</p>
<p>例如，要在 Linux x86-64 中下载 1.36.0 版本，请输入：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -LO https://dl.k8s.io/release/v1.36.0/bin/linux/amd64/kubectl
</span></span></code></pre></div>   <!--
   And for Linux ARM64, type:
   -->
<p>对于 Linux ARM64 来说，请输入：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -LO https://dl.k8s.io/release/v1.36.0/bin/linux/arm64/kubectl
</span></span></code></pre></div></div>


<!--
1. Validate the binary (optional)

   Download the kubectl checksum file:
-->
2. 验证该可执行文件（可选步骤）

   下载 kubectl 校验和文件：

   <ul class="nav nav-tabs" id="tabs-download-checksum-linux" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-download-checksum-linux-0" role="tab" aria-controls="tabs-download-checksum-linux-0" aria-selected="true">x86-64</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-download-checksum-linux-1" role="tab" aria-controls="tabs-download-checksum-linux-1">ARM64</a></li></ul>

<div class="tab-content" id="tabs-download-checksum-linux-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-download-checksum-linux-0" role="tabpanel" aria-labelledby="tabs-download-checksum-linux-0-tab" tabindex="download-checksum-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/amd64/kubectl.sha256&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-download-checksum-linux-1" role="tabpanel" aria-labelledby="tabs-download-checksum-linux-1-tab" tabindex="download-checksum-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/arm64/kubectl.sha256&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div></div>


   <!--
   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` 将以非零值退出，并打印如下输出：

   ```console
   kubectl: FAILED
   sha256sum: WARNING: 1 computed checksum did NOT match
   ```

   
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
   Download the same version of the binary and checksum.
   -->
<p>下载的 kubectl 与校验和文件版本必须相同。</p></div>


<!--
1. Install kubectl
-->
3. 安装 kubectl：

   ```bash
   sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
   ```

   
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
   If you do not have root access on the target system, you can still install
   kubectl to the `~/.local/bin` directory:
   -->
<p>即使你没有目标系统的 root 权限，仍然可以将 kubectl 安装到目录 <code>~/.local/bin</code> 中：</p>
   <!--
   # and then append (or prepend) ~/.local/bin to $PATH
   -->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chmod +x kubectl
</span></span><span class="line"><span class="cl">mkdir -p ~/.local/bin
</span></span><span class="line"><span class="cl">mv ./kubectl ~/.local/bin/kubectl
</span></span><span class="line"><span class="cl"><span class="c1"># 之后将 ~/.local/bin 附加（或前置）到 $PATH</span>
</span></span></code></pre></div></div>


<!--
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
   ```

   <!--
   Or use this for detailed view of version:
   -->
   或者使用如下命令来查看版本的详细信息：

   ```cmd
   kubectl version --client --output=yaml
   ```

<!--
### Install using native package management
-->
### 用原生包管理工具安装 {#install-using-native-package-management}

<ul class="nav nav-tabs" id="tabs-kubectl-install" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-kubectl-install-0" role="tab" aria-controls="tabs-kubectl-install-0" aria-selected="true">基于 Debian 的发行版</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-kubectl-install-1" role="tab" aria-controls="tabs-kubectl-install-1">基于 Red Hat 的发行版</a></li>
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-kubectl-install-2" role="tab" aria-controls="tabs-kubectl-install-2">基于 SUSE 的发行版</a></li></ul>

<div class="tab-content" id="tabs-kubectl-install-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-kubectl-install-0" role="tabpanel" aria-labelledby="tabs-kubectl-install-0-tab" tabindex="kubectl-install"><!--
1. Update the `apt` package index and install packages needed to use the Kubernetes `apt` repository:
-->
<ol>
<li>
<p>更新 <code>apt</code> 包索引，并安装使用 Kubernetes <code>apt</code> 仓库所需要的包：</p>
<!--
```shell
sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
```
-->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">sudo apt-get update
</span></span><span class="line"><span class="cl"><span class="c1"># apt-transport-https 可以是一个虚拟包；如果是这样，你可以跳过这个包</span>
</span></span><span class="line"><span class="cl">sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
</span></span></code></pre></div></li>
</ol>
<!--
2. Download the public signing key for the Kubernetes package repositories. The same signing key is used for all repositories so you can disregard the version in the URL:
-->
<ol start="2">
<li>
<p>下载 Kubernetes 软件包仓库的公共签名密钥。
同一个签名密钥适用于所有仓库，因此你可以忽略 URL 中的版本信息：</p>
<!--
# If the folder `/etc/apt/keyrings` does not exist, it should be created before the curl command, read the note below.
# sudo mkdir -p -m 755 /etc/apt/keyrings
-->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 如果 `/etc/apt/keyrings` 目录不存在，则应在 curl 命令之前创建它，请阅读下面的注释。</span>
</span></span><span class="line"><span class="cl"><span class="c1"># sudo mkdir -p -m 755 /etc/apt/keyrings</span>
</span></span><span class="line"><span class="cl">curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.36/deb/Release.key <span class="p">|</span> sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
</span></span><span class="line"><span class="cl">sudo chmod <span class="m">644</span> /etc/apt/keyrings/kubernetes-apt-keyring.gpg <span class="c1"># allow unprivileged APT programs to read this keyring   </span>
</span></span></code></pre></div></li>
</ol>
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
In releases older than Debian 12 and Ubuntu 22.04, folder `/etc/apt/keyrings` does not exist by default, and it should be created before the curl command.
-->
<p>在低于 Debian 12 和 Ubuntu 22.04 的发行版本中，<code>/etc/apt/keyrings</code> 默认不存在。
应在 curl 命令之前创建它。</p></div>
<!--
3. Add the appropriate Kubernetes `apt` repository. If you want to use Kubernetes version different than v1.36,
   replace v1.36 with the desired minor version in the command below:
-->
<ol start="3">
<li>
<p>添加合适的 Kubernetes <code>apt</code> 仓库。如果你想用 v1.36 之外的 Kubernetes 版本，
请将下面命令中的 v1.36 替换为所需的次要版本：</p>
<!--
```shell
# This overwrites any existing configuration in /etc/apt/sources.list.d/kubernetes.list
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.36/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list   # helps tools such as command-not-found to work correctly
```
-->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 这会覆盖 /etc/apt/sources.list.d/kubernetes.list 中的所有现存配置</span>
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.36/deb/ /&#39;</span> <span class="p">|</span> sudo tee /etc/apt/sources.list.d/kubernetes.list
</span></span><span class="line"><span class="cl">sudo chmod <span class="m">644</span> /etc/apt/sources.list.d/kubernetes.list   <span class="c1"># 有助于让诸如 command-not-found 等工具正常工作</span>
</span></span></code></pre></div></li>
</ol>
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/apt/sources.list.d/kubernetes.list` before running `apt-get update` and `apt-get upgrade`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
-->
<p>要将 kubectl 升级到别的次要版本，你需要先升级 <code>/etc/apt/sources.list.d/kubernetes.list</code> 中的版本，
再运行 <code>apt-get update</code> 和 <code>apt-get upgrade</code> 命令。
更详细的步骤可以在<a href="/zh-cn/docs/tasks/administer-cluster/kubeadm/change-package-repository/">更改 Kubernetes 软件包存储库</a>中找到。</p></div>
<!--
4. Update `apt` package index, then install kubectl:
-->
<ol start="4">
<li>
<p>更新 <code>apt</code> 包索引，然后安装 kubectl：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">sudo apt-get update
</span></span><span class="line"><span class="cl">sudo apt-get install -y kubectl
</span></span></code></pre></div></li>
</ol>
</div><div class="tab-body tab-pane fade"
        id="tabs-kubectl-install-1" role="tabpanel" aria-labelledby="tabs-kubectl-install-1-tab" tabindex="kubectl-install"><!--
1. Add the Kubernetes `yum` repository. If you want to use Kubernetes version
   different than v1.36, replace v1.36 with
   the desired minor version in the command below.
-->
<ol>
<li>
<p>添加 Kubernetes 的 <code>yum</code> 仓库。如果你想使用 v1.36 之外的 Kubernetes 版本，
将下面命令中的 v1.36 替换为所需的次要版本。</p>
<!--
```bash
# This overwrites any existing configuration in /etc/yum.repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
EOF
```
-->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 这会覆盖 /etc/yum.repos.d/kubernetes.repo 中现存的所有配置</span>
</span></span><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
</span></span></span><span class="line"><span class="cl"><span class="s">[kubernetes]
</span></span></span><span class="line"><span class="cl"><span class="s">name=Kubernetes
</span></span></span><span class="line"><span class="cl"><span class="s">baseurl=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/
</span></span></span><span class="line"><span class="cl"><span class="s">enabled=1
</span></span></span><span class="line"><span class="cl"><span class="s">gpgcheck=1
</span></span></span><span class="line"><span class="cl"><span class="s">gpgkey=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div></li>
</ol>
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/yum.repos.d/kubernetes.repo` before running `yum update`. This procedure is described in more detail in [Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
-->
<p>要将 kubectl 升级到别的次要版本，你需要先升级 <code>/etc/yum.repos.d/kubernetes.repo</code>
中的版本，再运行 <code>yum update</code> 命令。
更详细的步骤可以在<a href="/zh-cn/docs/tasks/administer-cluster/kubeadm/change-package-repository/">更改 Kubernetes 软件包存储库</a>中找到。</p></div>
<!--
2. Install kubectl using `yum`:
-->
<ol start="2">
<li>
<p>使用 <code>yum</code> 安装 kubectl：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo yum install -y kubectl
</span></span></code></pre></div></li>
</ol>
</div><div class="tab-body tab-pane fade"
        id="tabs-kubectl-install-2" role="tabpanel" aria-labelledby="tabs-kubectl-install-2-tab" tabindex="kubectl-install"><!-- 
1. Add the Kubernetes `zypper` repository. If you want to use Kubernetes version
different than v1.36, replace v1.36 with
the desired minor version in the command below.
-->
<ol>
<li>添加 Kubernetes <code>zypper</code> 软件源。如果你想使用不同于 v1.36
的 Kubernetes 版本，请在下面的命令中将 v1.36 替换为所需的次要版本。</li>
</ol>
<!-- 
```bash
# This overwrites any existing configuration in /etc/zypp/repos.d/kubernetes.repo
cat <<EOF | sudo tee /etc/zypp/repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
EOF
```
-->
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 这将覆盖 /etc/zypp/repos.d/kubernetes.repo 中的任何现有配置。</span>
</span></span><span class="line"><span class="cl">cat <span class="s">&lt;&lt;EOF | sudo tee /etc/zypp/repos.d/kubernetes.repo
</span></span></span><span class="line"><span class="cl"><span class="s">[kubernetes]
</span></span></span><span class="line"><span class="cl"><span class="s">name=Kubernetes
</span></span></span><span class="line"><span class="cl"><span class="s">baseurl=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/
</span></span></span><span class="line"><span class="cl"><span class="s">enabled=1
</span></span></span><span class="line"><span class="cl"><span class="s">gpgcheck=1
</span></span></span><span class="line"><span class="cl"><span class="s">gpgkey=https://pkgs.k8s.io/core:/stable:/v1.36/rpm/repodata/repomd.xml.key
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span></code></pre></div><div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
To upgrade kubectl to another minor release, you'll need to bump the version in `/etc/zypp/repos.d/kubernetes.repo` before running `zypper update`. This procedure is described in more detail in
[Changing The Kubernetes Package Repository](/docs/tasks/administer-cluster/kubeadm/change-package-repository/).
-->
<p>要升级 kubectl 到另一个小版本，你需要先更新 <code>/etc/zypp/repos.d/kubernetes.repo</code> 的版本，
再运行 <code>zypper update</code>。
此过程在<a href="/zh-cn/docs/tasks/administer-cluster/kubeadm/change-package-repository/">更改 Kubernetes 软件包仓库</a>中有更详细的描述。</p></div>
<!--
2. Update `zypper` and confirm the new repo addition:
-->
<ol start="2">
<li>
<p>更新 zypper 并确认新的仓库已添加：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo zypper update
</span></span></code></pre></div><!--
When this message appears, press 't' or 'a':
-->
<p>出现此信息时，按 't' 或 'a''：</p>
<pre tabindex="0"><code>New repository or package signing key received:

Repository:       Kubernetes
Key Fingerprint:  1111 2222 3333 4444 5555 6666 7777 8888 9999 AAAA
Key Name:         isv:kubernetes OBS Project &lt;isv:kubernetes@build.opensuse.org&gt;
Key Algorithm:    RSA 2048
Key Created:      Thu 25 Aug 2022 01:21:11 PM -03
Key Expires:      Sat 02 Nov 2024 01:21:11 PM -03 (expires in 85 days)
Rpm Name:         gpg-pubkey-9a296436-6307a177

Note: Signing data enables the recipient to verify that no modifications occurred after the data
were signed. Accepting data with no, wrong or unknown signature can lead to a corrupted system
and in extreme cases even to a system compromise.

Note: A GPG pubkey is clearly identified by its fingerprint. Do not rely on the key&#39;s name. If
you are not sure whether the presented key is authentic, ask the repository provider or check
their web site. Many providers maintain a web page showing the fingerprints of the GPG keys they
are using.

Do you want to reject the key, trust temporarily, or trust always? [r/t/a/?] (r): a
</code></pre></li>
</ol>
<!--
3. Install kubectl using `zypper`:
-->
<ol start="3">
<li>
<p>使用 <code>zypper</code> 安装 kubectl：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo zypper install -y kubectl
</span></span></code></pre></div></li>
</ol>
</div></div>


<!--
### Install using other package management
-->
### 用其他包管理工具安装 {#install-using-other-package-management}

<ul class="nav nav-tabs" id="tabs-other-kubectl-install" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-other-kubectl-install-0" role="tab" aria-controls="tabs-other-kubectl-install-0" aria-selected="true">Snap</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-other-kubectl-install-1" role="tab" aria-controls="tabs-other-kubectl-install-1">Homebrew</a></li></ul>

<div class="tab-content" id="tabs-other-kubectl-install-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-other-kubectl-install-0" role="tabpanel" aria-labelledby="tabs-other-kubectl-install-0-tab" tabindex="other-kubectl-install"><!--
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.
-->
<p>如果你使用的 Ubuntu 或其他 Linux 发行版，内建支持
<a href="https://snapcraft.io/docs/core/install">snap</a> 包管理工具，
则可用 <a href="https://snapcraft.io/">snap</a> 命令安装 kubectl。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">snap install kubectl --classic
</span></span><span class="line"><span class="cl">kubectl version --client
</span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-other-kubectl-install-1" role="tabpanel" aria-labelledby="tabs-other-kubectl-install-1-tab" tabindex="other-kubectl-install"><!--
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).
-->
<p>如果你使用 Linux 系统，并且装了 <a href="https://docs.brew.sh/Homebrew-on-Linux">Homebrew</a>
包管理工具，
则可以使用这种方式<a href="https://docs.brew.sh/Homebrew-on-Linux#install">安装</a> kubectl。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">brew install kubectl
</span></span><span class="line"><span class="cl">kubectl version --client
</span></span></code></pre></div></div></div>


<!--
## Verify kubectl configuration
-->
## 验证 kubectl 配置 {#verify-kubectl-configuration}


	<!-- 
title: "verify kubectl install"
description: "How to verify kubectl."
headless: true
build:
  list: never
  render: never
  publishResources: false
-->
<!-- 
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:
-->
<p>为了让 kubectl 能发现并访问 Kubernetes 集群，你需要一个
<a href="/zh-cn/docs/concepts/configuration/organize-cluster-access-kubeconfig/">kubeconfig 文件</a>，
该文件在
<a href="https://github.com/kubernetes/kubernetes/blob/master/cluster/kube-up.sh">kube-up.sh</a>
创建集群时，或成功部署一个 Minikube 集群时，均会自动生成。
通常，kubectl 的配置信息存放于文件 <code>~/.kube/config</code> 中。</p>
<p>通过获取集群状态的方法，检查是否已恰当地配置了 kubectl：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">kubectl cluster-info
</span></span></code></pre></div><!-- 
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.
-->
<p>如果返回一个 URL，则意味着 kubectl 成功地访问到了你的集群。</p>
<p>如果你看到如下所示的消息，则代表 kubectl 配置出了问题，或无法连接到 Kubernetes 集群。</p>
<pre tabindex="0"><code>The connection to the server &lt;server-name:port&gt; was refused - did you specify the right host or port?
（访问 &lt;server-name:port&gt; 被拒绝 - 你指定的主机和端口是否有误？）
</code></pre><!-- 
For example, if you are intending to run a Kubernetes cluster on your laptop (locally),
you will need a tool like [Minikube](https://minikube.sigs.k8s.io/docs/start/) 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,
check whether it is configured properly using the following command:
-->
<p>例如，如果你想在自己的笔记本上（本地）运行 Kubernetes 集群，你需要先安装一个
<a href="https://minikube.sigs.k8s.io/docs/start/">Minikube</a>
这样的工具，然后再重新运行上面的命令。</p>
<p>如果命令 <code>kubectl cluster-info</code> 返回了 URL，但你还不能访问集群，
那可以用以下命令来检查配置是否妥当：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">kubectl cluster-info dump
</span></span></code></pre></div><!--
### Troubleshooting the 'No Auth Provider Found' error message {#no-auth-provider-found}

In Kubernetes 1.26, kubectl removed the built-in authentication for the following cloud
providers' managed Kubernetes offerings. These providers have released kubectl plugins
to provide the cloud-specific authentication. For instructions, refer to the following provider documentation:
-->
<h3 id="no-auth-provider-found">排查&quot;找不到身份验证提供商&quot;的错误信息<a class="td-heading-self-link" href="#no-auth-provider-found" aria-label="Heading self-link"></a></h3>
<p>在 Kubernetes 1.26 中，kubectl 删除了以下云提供商托管的 Kubernetes 产品的内置身份验证。
这些提供商已经发布了 kubectl 插件来提供特定于云的身份验证。
有关说明，请参阅以下提供商文档：</p>
<!--
* Azure AKS: [kubelogin plugin](https://azure.github.io/kubelogin/)
* Google Kubernetes Engine: [gke-gcloud-auth-plugin](https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin)
-->
<ul>
<li>Azure AKS：<a href="https://azure.github.io/kubelogin/">kubelogin 插件</a></li>
<li>CKE：<a href="https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl#install_plugin">gke-gcloud-auth-plugin</a></li>
</ul>
<!--
There could also be other causes for the same error message that are unrelated
to that change.
-->
<p>也可能存在其他与此更改无关的原因导致出现相同的错误消息。</p>


<!--
## 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 设置自动补全功能的操作步骤。

<ul class="nav nav-tabs" id="tabs-kubectl-autocompletion" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-kubectl-autocompletion-0" role="tab" aria-controls="tabs-kubectl-autocompletion-0" aria-selected="true">Bash</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-kubectl-autocompletion-1" role="tab" aria-controls="tabs-kubectl-autocompletion-1">Fish</a></li>
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-kubectl-autocompletion-2" role="tab" aria-controls="tabs-kubectl-autocompletion-2">Zsh</a></li></ul>

<div class="tab-content" id="tabs-kubectl-autocompletion-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-kubectl-autocompletion-0" role="tabpanel" aria-labelledby="tabs-kubectl-autocompletion-0-tab" tabindex="kubectl-autocompletion"><!-- 
title: "bash auto-completion on Linux"
description: "Some optional configuration for bash auto-completion on Linux."
headless: true
build:
  list: never
  render: never
  publishResources: false
-->
<!-- 
### Introduction
-->
<h3 id="introduction">简介<a class="td-heading-self-link" href="#introduction" aria-label="Heading self-link"></a></h3>
<!-- 
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`).
-->
<p>kubectl 的 Bash 补全脚本可以用命令 <code>kubectl completion bash</code> 生成。
在 Shell 中导入（Sourcing）补全脚本，将启用 kubectl 自动补全功能。</p>
<p>然而，补全脚本依赖于工具 <a href="https://github.com/scop/bash-completion"><strong>bash-completion</strong></a>，
所以要先安装它（可以用命令 <code>type _init_completion</code> 检查 bash-completion 是否已安装）。</p>
<!-- 
### Install bash-completion
-->
<h3 id="install-bash-comletion">安装 bash-completion<a class="td-heading-self-link" href="#install-bash-comletion" aria-label="Heading self-link"></a></h3>
<!-- 
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:
-->
<p>很多包管理工具均支持 bash-completion（参见<a href="https://github.com/scop/bash-completion#installation">这里</a>）。
可以通过 <code>apt-get install bash-completion</code> 或 <code>yum install bash-completion</code> 等命令来安装它。</p>
<p>上述命令将创建文件 <code>/usr/share/bash-completion/bash_completion</code>，它是 bash-completion 的主脚本。
依据包管理工具的实际情况，你需要在 <code>~/.bashrc</code> 文件中手工导入此文件。</p>
<p>要查看结果，请重新加载你的 Shell，并运行命令 <code>type _init_completion</code>。
如果命令执行成功，则设置完成，否则将下面内容添加到文件 <code>~/.bashrc</code> 中：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">source</span> /usr/share/bash-completion/bash_completion
</span></span></code></pre></div><!-- 
Reload your shell and verify that bash-completion is correctly installed by typing `type _init_completion`.
-->
<p>重新加载 Shell，再输入命令 <code>type _init_completion</code> 来验证 bash-completion 的安装状态。</p>
<!-- 
### Enable kubectl autocompletion
-->
<h3 id="enable-kubectl-autocompletion">启动 kubectl 自动补全功能<a class="td-heading-self-link" href="#enable-kubectl-autocompletion" aria-label="Heading self-link"></a></h3>
<h4 id="bash">Bash<a class="td-heading-self-link" href="#bash" aria-label="Heading self-link"></a></h4>
<!-- 
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:
-->
<p>你现在需要确保一点：kubectl 补全脚本已经导入（sourced）到 Shell 会话中。
可以通过以下两种方法进行设置：</p>
<ul class="nav nav-tabs" id="tabs-kubectl-bash-autocompletion" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-kubectl-bash-autocompletion-0" role="tab" aria-controls="tabs-kubectl-bash-autocompletion-0" aria-selected="true">当前用户</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-kubectl-bash-autocompletion-1" role="tab" aria-controls="tabs-kubectl-bash-autocompletion-1">系统全局</a></li></ul>

<div class="tab-content" id="tabs-kubectl-bash-autocompletion-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-kubectl-bash-autocompletion-0" role="tabpanel" aria-labelledby="tabs-kubectl-bash-autocompletion-0-tab" tabindex="kubectl-bash-autocompletion"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;source &lt;(kubectl completion bash)&#39;</span> &gt;&gt;~/.bashrc
</span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-kubectl-bash-autocompletion-1" role="tabpanel" aria-labelledby="tabs-kubectl-bash-autocompletion-1-tab" tabindex="kubectl-bash-autocompletion"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">kubectl completion bash <span class="p">|</span> sudo tee /etc/bash_completion.d/kubectl &gt; /dev/null
</span></span><span class="line"><span class="cl">sudo chmod a+r /etc/bash_completion.d/kubectl
</span></span></code></pre></div></div></div>

<!-- 
If you have an alias for kubectl, you can extend shell completion to work with that alias:
-->
<p>如果 kubectl 有关联的别名，你可以扩展 Shell 补全来适配此别名：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;alias k=kubectl&#39;</span> &gt;&gt;~/.bashrc
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;complete -o default -F __start_kubectl k&#39;</span> &gt;&gt;~/.bashrc
</span></span></code></pre></div>
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!-- 
bash-completion sources all completion scripts in `/etc/bash_completion.d`.
-->
<p>bash-completion 负责导入 <code>/etc/bash_completion.d</code> 目录中的所有补全脚本。</p></div>

<!-- 
Both approaches are equivalent. After reloading your shell, kubectl autocompletion should be working.
To enable bash autocompletion in current session of shell, source the ~/.bashrc file:
-->
<p>两种方式的效果相同。重新加载 Shell 后，kubectl 自动补全功能即可生效。
若要在当前 Shell 会话中启用 Bash 补全功能，源引 <code>~/.bashrc</code> 文件：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nb">source</span> ~/.bashrc
</span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-kubectl-autocompletion-1" role="tabpanel" aria-labelledby="tabs-kubectl-autocompletion-1-tab" tabindex="kubectl-autocompletion"><!--
title: "fish auto-completion"
description: "Optional configuration to enable fish shell auto-completion."
headless: true
build:
  list: never
  render: never
  publishResources: false
-->

<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
Autocomplete for Fish requires kubectl 1.23 or later.
-->
<p>自动补全 Fish 需要 kubectl 1.23 或更高版本。</p></div>

<!--
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:
-->
<p>kubectl 通过命令 <code>kubectl completion fish</code> 生成 Fish 自动补全脚本。
在 shell 中导入（Sourcing）该自动补全脚本，将启动 kubectl 自动补全功能。</p>
<p>为了在所有的 shell 会话中实现此功能，请将下面内容加入到文件 <code>~/.config/fish/config.fish</code> 中。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">kubectl completion fish <span class="p">|</span> <span class="nb">source</span>
</span></span></code></pre></div><!--
After reloading your shell, kubectl autocompletion should be working.
-->
<p>重新加载 shell 后，kubectl 自动补全功能将立即生效。</p>
</div><div class="tab-body tab-pane fade"
        id="tabs-kubectl-autocompletion-2" role="tabpanel" aria-labelledby="tabs-kubectl-autocompletion-2-tab" tabindex="kubectl-autocompletion"><!-- 
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:
-->
<p>kubectl 通过命令 <code>kubectl completion zsh</code> 生成 Zsh 自动补全脚本。
在 Shell 中导入（Sourcing）该自动补全脚本，将启动 kubectl 自动补全功能。</p>
<p>为了在所有的 Shell 会话中实现此功能，请将下面内容加入到文件 <code>~/.zshrc</code> 中。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-zsh" data-lang="zsh"><span class="line"><span class="cl"><span class="nb">source</span> &lt;<span class="o">(</span>kubectl completion zsh<span class="o">)</span>
</span></span></code></pre></div><!-- 
If you have an alias for kubectl, kubectl autocompletion will automatically work with it.
-->
<p>如果你为 kubectl 定义了别名，kubectl 自动补全将自动使用它。</p>
<!-- 
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:
-->
<p>重新加载 Shell 后，kubectl 自动补全功能将立即生效。</p>
<p>如果你收到 <code>2: command not found: compdef</code> 这样的错误提示，那请将下面内容添加到
<code>~/.zshrc</code> 文件的开头：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-zsh" data-lang="zsh"><span class="line"><span class="cl">autoload -Uz compinit
</span></span><span class="line"><span class="cl">compinit
</span></span></code></pre></div></div></div>


<!--
### Configure kuberc

See [kuberc](/docs/reference/kubectl/kuberc) for more information.
-->
### 配置 kuberc  {#configure-kuberc}

更多信息请参见 [kuberc](/zh-cn/docs/reference/kubectl/kuberc)。

<!--
### Install `kubectl convert` plugin
-->
### 安装 `kubectl convert` 插件 {#install-kubectl-convert-plugin}


	<!--
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)
-->
<p>一个 Kubernetes 命令行工具 <code>kubectl</code> 的插件，允许你将清单在不同 API 版本间转换。
这对于将清单迁移到新的 Kubernetes 发行版上未被废弃的 API 版本时尤其有帮助。
更多信息请访问<a href="/zh-cn/docs/reference/using-api/deprecation-guide/#migrate-to-non-deprecated-apis">迁移到非弃用 API</a></p>


<!--
1. Download the latest release with the command:
-->
1. 用以下命令下载最新发行版：

   <ul class="nav nav-tabs" id="tabs-download-convert-binary-linux" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-download-convert-binary-linux-0" role="tab" aria-controls="tabs-download-convert-binary-linux-0" aria-selected="true">x86-64</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-download-convert-binary-linux-1" role="tab" aria-controls="tabs-download-convert-binary-linux-1">ARM64</a></li></ul>

<div class="tab-content" id="tabs-download-convert-binary-linux-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-download-convert-binary-linux-0" role="tabpanel" aria-labelledby="tabs-download-convert-binary-linux-0-tab" tabindex="download-convert-binary-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/amd64/kubectl-convert&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-download-convert-binary-linux-1" role="tabpanel" aria-labelledby="tabs-download-convert-binary-linux-1-tab" tabindex="download-convert-binary-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/arm64/kubectl-convert&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div></div>


<!--
1. Validate the binary (optional)

   Download the kubectl-convert checksum file:
-->
2. 验证该可执行文件（可选步骤）

   下载 kubectl-convert 校验和文件：

   <ul class="nav nav-tabs" id="tabs-download-convert-checksum-linux" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-download-convert-checksum-linux-0" role="tab" aria-controls="tabs-download-convert-checksum-linux-0" aria-selected="true">x86-64</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-download-convert-checksum-linux-1" role="tab" aria-controls="tabs-download-convert-checksum-linux-1">ARM64</a></li></ul>

<div class="tab-content" id="tabs-download-convert-checksum-linux-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-download-convert-checksum-linux-0" role="tabpanel" aria-labelledby="tabs-download-convert-checksum-linux-0-tab" tabindex="download-convert-checksum-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/amd64/kubectl-convert.sha256&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div><div class="tab-body tab-pane fade"
        id="tabs-download-convert-checksum-linux-1" role="tabpanel" aria-labelledby="tabs-download-convert-checksum-linux-1-tab" tabindex="download-convert-checksum-linux"><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">   curl -LO <span class="s2">&#34;https://dl.k8s.io/release/</span><span class="k">$(</span>curl -L -s https://dl.k8s.io/release/stable.txt<span class="k">)</span><span class="s2">/bin/linux/arm64/kubectl-convert.sha256&#34;</span>
</span></span><span class="line"><span class="cl">   </span></span></code></pre></div></div></div>


   <!--
   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` 将以非零值退出，并打印输出类似于：

   ```console
   kubectl-convert: FAILED
   sha256sum: WARNING: 1 computed checksum did NOT match
   ```

   
<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
   Download the same version of the binary and checksum.
   -->
<p>下载相同版本的可执行文件和校验和。</p></div>


<!--
1. Install kubectl-convert
-->
3. 安装 kubectl-convert

   ```bash
   sudo install -o root -g root -m 0755 kubectl-convert /usr/local/bin/kubectl-convert
   ```

<!--
1. Verify plugin is successfully installed
-->
4. 验证插件是否安装成功

   ```shell
   kubectl convert --help
   ```

   <!--
   If you do not see an error, it means the plugin is successfully installed.
   -->
   如果你没有看到任何错误就代表插件安装成功了。

<!--
1. After installing the plugin, clean up the installation files:
-->
5. 安装插件后，清理安装文件：

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

## 接下来


	<!-- 
title: "What's next?"
description: "What's next after installing kubectl."
headless: true
-->
<!-- 
* Learn about [kubectl](/docs/concepts/overview/kubectl/) and its role in the Kubernetes ecosystem.
* [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/)
-->
<ul>
<li>了解 <a href="/zh-cn/docs/concepts/overview/kubectl/">kubectl</a> 及其在 Kubernetes 生态系统中的作用。</li>
<li><a href="https://minikube.sigs.k8s.io/docs/start/">安装 Minikube</a>。</li>
<li>有关创建集群的更多信息，请参阅<a href="/zh-cn/docs/setup/">入门指南</a>。</li>
<li><a href="/zh-cn/docs/tasks/access-application-cluster/service-access-application-cluster/">学习如何启动并对外公开你的应用程序</a>。</li>
<li>如果你需要访问其他人创建的集群，
请参阅<a href="/zh-cn/docs/tasks/access-application-cluster/configure-access-multiple-clusters/">共享集群接入文档</a>。</li>
<li>阅读 <a href="/zh-cn/docs/reference/kubectl/kubectl/">kubectl 参考文档</a>。</li>
</ul>
