# 更改 Kubernetes 软件包仓库

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

---

<!--
title: Changing The Kubernetes Package Repository
content_type: task
weight: 150
-->

<!-- overview -->

<!--
This page explains how to enable a package repository for the desired
Kubernetes minor release upon upgrading a cluster. This is only needed
for users of the community-owned package repositories hosted at `pkgs.k8s.io`.
Unlike the legacy package repositories, the community-owned package
repositories are structured in a way that there's a dedicated package
repository for each Kubernetes minor version.
-->
本页介绍了如何在升级集群时启用包含 Kubernetes 次要版本的软件包仓库。
这仅适用于使用托管在 `pkgs.k8s.io` 上社区自治软件包仓库的用户。
启用新的 Kubernetes 小版本的软件包仓库。与传统的软件包仓库不同，
社区自治的软件包仓库所采用的结构为每个 Kubernetes 小版本都有一个专门的软件包仓库。


<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
This guide only covers a part of the Kubernetes upgrade process. Please see the
[upgrade guide](/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/) for
more information about upgrading Kubernetes clusters.
-->
<p>本指南仅介绍 Kubernetes 升级过程的一部分。
有关升级 Kubernetes 集群的更多信息，
请参阅<a href="/zh-cn/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/">升级指南</a>。</p></div>



<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
This step is only needed upon upgrading a cluster to another **minor** release.
If you're upgrading to another patch release within the same minor release (e.g.
v1.36.5 to v1.36.7), you don't
need to follow this guide. However, if you're still using the legacy package
repositories, you'll need to migrate to the new community-owned package
repositories before upgrading (see the next section for more details on how to
do this).
-->
<p>仅在将集群升级到另一个<strong>次要</strong>版本时才需要执行此步骤。
如果你要升级到同一次要版本中的另一个补丁版本（例如：v1.36.5 到
v1.36.7）则不需要遵循本指南。
但是，如果你仍在使用旧的软件包仓库，则需要在升级之前迁移到社区自治的新软件包仓库
（有关如何执行此操作的更多详细信息，请参阅下一节）。</p></div>


## 准备开始

<!--
This document assumes that you're already using the community-owned
package repositories (`pkgs.k8s.io`). If that's not the case, it's strongly
recommended to migrate to the community-owned package repositories as described
in the [official announcement](/blog/2023/08/15/pkgs-k8s-io-introduction/).
-->
本文假设你已经在使用社区自治的软件包仓库（`pkgs.k8s.io`）。如果不是这种情况，
强烈建议按照[官方公告](/zh-cn/blog/2023/08/15/pkgs-k8s-io-introduction/)中所述，
迁移到社区自治的软件包仓库。

<div class="alert alert-secondary callout note" role="note">
  <strong>说明：</strong> 自 2023 年 9 月 13 日起，Kubernetes 已经<a href="/zh-cn/blog/2023/08/31/legacy-package-repository-deprecation/">弃用并冻结了旧版软件包仓库 (<code>apt.kubernetes.io</code> 和<code>yum.kubernetes.io</code>)。</a>
<strong>强烈建议使用<a href="/zh-cn/blog/2023/08/15/pkgs-k8s-io-introduction/">托管在 <code>pkgs.k8s.io</code> 上的新软件包仓库</a>来安装 2023 年 9 月 13 日之后发布的 Kubernetes 版本。</strong>
旧版软件包仓库已被弃用，其内容可能在未来的任何时间被删除，恕不另行通知。新的软件包仓库提供了从 Kubernetes v1.24.0 版本开始的下载。
</div>


<!--
### Verifying if the Kubernetes package repositories are used

If you're unsure whether you're using the community-owned package repositories or the
legacy package repositories, take the following steps to verify:
-->
### 验证是否正在使用 Kubernetes 软件包仓库

如果你不确定自己是在使用社区自治的软件包仓库还是在使用老旧的软件包仓库，
可以执行以下步骤进行验证：

<ul class="nav nav-tabs" id="tabs-k8s-install-versions" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-k8s-install-versions-0" role="tab" aria-controls="tabs-k8s-install-versions-0" aria-selected="true">Ubuntu、Debian 或 HypriotOS</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-k8s-install-versions-1" role="tab" aria-controls="tabs-k8s-install-versions-1">CentOS、RHEL 或 Fedora</a></li>
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-k8s-install-versions-2" role="tab" aria-controls="tabs-k8s-install-versions-2">openSUSE 或 SLES</a></li></ul>

<div class="tab-content" id="tabs-k8s-install-versions-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-k8s-install-versions-0" role="tabpanel" aria-labelledby="tabs-k8s-install-versions-0-tab" tabindex="k8s-install-versions"><!--
Print the contents of the file that defines the Kubernetes `apt` repository:

```shell
# On your system, this configuration file could have a different name
pager /etc/apt/sources.list.d/kubernetes.list
```

If you see a line similar to:
-->
<p>打印定义 Kubernetes <code>apt</code> 仓库的文件的内容：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 在你的系统上，此配置文件可能具有不同的名称</span>
</span></span><span class="line"><span class="cl">pager /etc/apt/sources.list.d/kubernetes.list
</span></span></code></pre></div><p>如果你看到类似以下的一行：</p>
<pre tabindex="0"><code>deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.35/deb/ /
</code></pre><!--
**You're using the Kubernetes package repositories and this guide applies to you.**
Otherwise, it's strongly recommended to migrate to the Kubernetes package repositories
as described in the [official announcement](/blog/2023/08/15/pkgs-k8s-io-introduction/).
-->
<p><strong>你正在使用 Kubernetes 软件包仓库，本指南适用于你。</strong>
否则，强烈建议按照<a href="/zh-cn/blog/2023/08/15/pkgs-k8s-io-introduction/">官方公告</a>中所述，
迁移到 Kubernetes 软件包仓库。</p>
</div><div class="tab-body tab-pane fade"
        id="tabs-k8s-install-versions-1" role="tabpanel" aria-labelledby="tabs-k8s-install-versions-1-tab" tabindex="k8s-install-versions"><!--
Print the contents of the file that defines the Kubernetes `yum` repository:

```shell
# On your system, this configuration file could have a different name
cat /etc/yum.repos.d/kubernetes.repo
```

If you see a `baseurl` similar to the `baseurl` in the output below:
-->
<p>打印定义 Kubernetes <code>yum</code> 仓库的文件的内容：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 在你的系统上，此配置文件可能具有不同的名称</span>
</span></span><span class="line"><span class="cl">cat /etc/yum.repos.d/kubernetes.repo
</span></span></code></pre></div><p>如果你看到的 <code>baseurl</code> 类似以下输出中的 <code>baseurl</code>：</p>
<pre tabindex="0"><code>[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl
</code></pre><!--
**You're using the Kubernetes package repositories and this guide applies to you.**
Otherwise, it's strongly recommended to migrate to the Kubernetes package repositories
as described in the [official announcement](/blog/2023/08/15/pkgs-k8s-io-introduction/).
-->
<p><strong>你正在使用 Kubernetes 软件包仓库，本指南适用于你。</strong>
否则，强烈建议按照<a href="/zh-cn/blog/2023/08/15/pkgs-k8s-io-introduction/">官方公告</a>中所述，
迁移到 Kubernetes 软件包仓库。</p>
</div><div class="tab-body tab-pane fade"
        id="tabs-k8s-install-versions-2" role="tabpanel" aria-labelledby="tabs-k8s-install-versions-2-tab" tabindex="k8s-install-versions"><!--
Print the contents of the file that defines the Kubernetes `zypper` repository:

```shell
# On your system, this configuration file could have a different name
cat /etc/zypp/repos.d/kubernetes.repo
```

If you see a `baseurl` similar to the `baseurl` in the output below:
-->
<p>打印定义 Kubernetes <code>zypper</code> 仓库的文件的内容：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="c1"># 在你的系统上，此配置文件可能具有不同的名称</span>
</span></span><span class="line"><span class="cl">cat /etc/zypp/repos.d/kubernetes.repo
</span></span></code></pre></div><p>如果你看到的 <code>baseurl</code> 类似以下输出中的 <code>baseurl</code>：</p>
<pre tabindex="0"><code>[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl
</code></pre><!--
**You're using the Kubernetes package repositories and this guide applies to you.**
Otherwise, it's strongly recommended to migrate to the Kubernetes package repositories
as described in the [official announcement](/blog/2023/08/15/pkgs-k8s-io-introduction/).
-->
<p><strong>你正在使用 Kubernetes 软件包仓库，本指南适用于你。</strong>
否则，强烈建议按照<a href="/zh-cn/blog/2023/08/15/pkgs-k8s-io-introduction/">官方公告</a>中所述，
迁移到 Kubernetes 软件包仓库。</p>
</div></div>



<div class="alert alert-info" role="note"><h4 class="alert-heading">说明：</h4><!--
The URL used for the Kubernetes package repositories is not limited to `pkgs.k8s.io`,
it can also be one of:
-->
<p>Kubernetes 软件包仓库所用的 URL 不仅限于 <code>pkgs.k8s.io</code>，还可以是以下之一：</p>
<ul>
<li><code>pkgs.k8s.io</code></li>
<li><code>pkgs.kubernetes.io</code></li>
<li><code>packages.kubernetes.io</code></li>
</ul></div>


<!-- steps -->

<!--
## Switching to another Kubernetes package repository

This step should be done upon upgrading from one to another Kubernetes minor
release in order to get access to the packages of the desired Kubernetes minor
version.
-->
## 切换到其他 Kubernetes 软件包仓库  {#switching-to-another-kubernetes-package-repository}

在从一个 Kubernetes 小版本升级到另一个版本时，应执行此步骤以获取所需 Kubernetes 小版本的软件包访问权限。

<ul class="nav nav-tabs" id="tabs-k8s-upgrade-versions" role="tablist"><li class="nav-item"><a data-bs-toggle="tab" class="nav-link active" href="#tabs-k8s-upgrade-versions-0" role="tab" aria-controls="tabs-k8s-upgrade-versions-0" aria-selected="true">Ubuntu、Debian 或 HypriotOS</a></li>
	  
		<li class="nav-item"><a data-bs-toggle="tab" class="nav-link" href="#tabs-k8s-upgrade-versions-1" role="tab" aria-controls="tabs-k8s-upgrade-versions-1">CentOS、RHEL 或 Fedora</a></li></ul>

<div class="tab-content" id="tabs-k8s-upgrade-versions-content"><div class="tab-body tab-pane fadeshow active"
        id="tabs-k8s-upgrade-versions-0" role="tabpanel" aria-labelledby="tabs-k8s-upgrade-versions-0-tab" tabindex="k8s-upgrade-versions"><!--
1. Open the file that defines the Kubernetes `apt` repository using a text editor of your choice:
-->
<ol>
<li>
<p>使用你所选择的文本编辑器打开定义 Kubernetes <code>apt</code> 仓库的文件：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">nano /etc/apt/sources.list.d/kubernetes.list
</span></span></code></pre></div><!--
You should see a single line with the URL that contains your current Kubernetes
minor version. For example, if you're using v1.35,
you should see this:
-->
<p>你应该看到一行包含当前 Kubernetes 小版本的 URL。
例如，如果你正在使用 v1.35，你应该看到类似以下的输出：</p>
<pre tabindex="0"><code>deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.35/deb/ /
</code></pre></li>
</ol>
<!--
1. Change the version in the URL to **the next available minor release**, for example:
-->
<ol start="2">
<li>
<p>将 URL 中的版本更改为<strong>下一个可用的小版本</strong>，例如：</p>
<pre tabindex="0"><code>deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.36/deb/ /
</code></pre></li>
</ol>
<!--
1. Save the file and exit your text editor. Continue following the relevant upgrade instructions.
-->
<ol start="3">
<li>保存文件并退出文本编辑器。继续按照相关的升级说明进行操作。</li>
</ol>
</div><div class="tab-body tab-pane fade"
        id="tabs-k8s-upgrade-versions-1" role="tabpanel" aria-labelledby="tabs-k8s-upgrade-versions-1-tab" tabindex="k8s-upgrade-versions"><!--
1. Open the file that defines the Kubernetes `yum` repository using a text editor of your choice:
-->
<ol>
<li>
<p>使用你所选择的文本编辑器打开定义 Kubernetes <code>yum</code> 仓库的文件：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">nano /etc/yum.repos.d/kubernetes.repo
</span></span></code></pre></div><!--
You should see a file with two URLs that contain your current Kubernetes
minor version. For example, if you're using v1.35,
you should see this:
-->
<p>你应该看到一个文件包含当前 Kubernetes 小版本的两个 URL。
例如，如果你正在使用 v1.35，你应该看到类似以下的输出：</p>
<pre tabindex="0"><code>[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.35/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
</code></pre></li>
</ol>
<!--
1. Change the version in these URLs to **the next available minor release**, for example:
-->
<ol start="2">
<li>
<p>将这些 URL 中的版本更改为<strong>下一个可用的小版本</strong>，例如：</p>
<pre tabindex="0"><code>[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
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
</code></pre></li>
</ol>
<!--
1. Save the file and exit your text editor. Continue following the relevant upgrade instructions.
-->
<ol start="3">
<li>保存文件并退出文本编辑器。继续按照相关的升级说明进行操作。</li>
</ol>
</div></div>


## 接下来

<!--
* See how to [Upgrade Linux nodes](/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/).
* See how to [Upgrade Windows nodes](/docs/tasks/administer-cluster/kubeadm/upgrading-windows-nodes/).
-->
* 参见如何[升级 Linux 节点的说明](/zh-cn/docs/tasks/administer-cluster/kubeadm/upgrading-linux-nodes/)。
* 参见如何[升级 Windows 节点的说明](/zh-cn/docs/tasks/administer-cluster/kubeadm/upgrading-windows-nodes/)。
