Merge pull request #26108 from tengqm/zh-resync-install-kubeadm

[zh] Resync install-kubeadm
This commit is contained in:
Kubernetes Prow Robot
2021-01-15 21:49:43 -08:00
committed by GitHub
@@ -37,11 +37,11 @@ For information how to create a cluster with kubeadm once you have performed thi
- Red Hat Enterprise Linux (RHEL) 7
- Fedora 25+
- HypriotOS v1.0.1+
- Container Linux (tested with 1800.6.0)
- Flatcar Container Linux (tested with 2512.3.0)
* 2 GB or more of RAM per machine (any less will leave little room for your apps)
* 2 CPUs or more
* Full network connectivity between all machines in the cluster (public or private network is fine)
* Unique hostname, MAC address, and product_uuid for every node. See [here](#verify-the-mac-address-and-product-uuid-are-unique-for-every-node) for more details.
* Unique hostname, MAC address, and product_uuid for every node. See [here](#verify-mac-address) for more details.
* Certain ports are open on your machines. See [here](#check-required-ports) for more details.
* Swap disabled. You **MUST** disable swap in order for the kubelet to work properly.
-->
@@ -52,13 +52,13 @@ For information how to create a cluster with kubeadm once you have performed thi
- Red Hat Enterprise Linux (RHEL) 7
- Fedora 25+
- HypriotOS v1.0.1+
- Container Linux (测试 1800.6.0 版本)
* 每台机器 2 GB 或更多的 RAM (如果少于这个数字将会影响应用的运行内存)
- Flatcar Container Linux (使用 2512.3.0 版本测试通过)
* 每台机器 2 GB 或更多的 RAM 如果少于这个数字将会影响应用的运行内存)
* 2 CPU 核或更多
* 集群中的所有机器的网络彼此均能相互连接(公网和内网都可以)
* 节点之中不可以有重复的主机名、MAC 地址或 product_uuid。请参见[这里](#verify-the-mac-address-and-product-uuid-are-unique-for-every-node) 了解更多详细信息。
* 节点之中不可以有重复的主机名、MAC 地址或 product_uuid。请参见[这里](#verify-mac-address)了解更多详细信息。
* 开启机器上的某些端口。请参见[这里](#check-required-ports) 了解更多详细信息。
* 禁用交换分区。为了保证 kubelet 正常工作, **必须** 禁用交换分区。
* 禁用交换分区。为了保证 kubelet 正常工作, **必须** 禁用交换分区。
<!-- steps -->
@@ -74,13 +74,15 @@ identical values. Kubernetes uses these values to uniquely identify the nodes in
If these values are not unique to each node, the installation process
may [fail](https://github.com/kubernetes/kubeadm/issues/31).
-->
## 确保每个节点上 MAC 地址和 product_uuid 的唯一性{#verify-the-mac-address-and-product-uuid-are-unique-for-every-node}
## 确保每个节点上 MAC 地址和 product_uuid 的唯一性 {#verify-mac-address}
* 可以使用命令 `ip link``ifconfig -a` 来获取网络接口的 MAC 地址
* 可以使用命令 `ip link``ifconfig -a` 来获取网络接口的 MAC 地址
* 可以使用 `sudo cat /sys/class/dmi/id/product_uuid` 命令对 product_uuid 校验
一般来讲,硬件设备会拥有唯一的地址,但是有些虚拟机的地址可能会重复。Kubernetes 使用这些值来唯一确定集群中的节点。
如果这些值在每个节点上不唯一,可能会导致安装[失败](https://github.com/kubernetes/kubeadm/issues/31)
一般来讲,硬件设备会拥有唯一的地址,但是有些虚拟机的地址可能会重复。
Kubernetes 使用这些值来唯一确定集群中的节点
如果这些值在每个节点上不唯一,可能会导致安装
[失败](https://github.com/kubernetes/kubeadm/issues/31)。
<!--
## Check network adapters
@@ -90,78 +92,72 @@ route, we recommend you add IP route(s) so Kubernetes cluster addresses go via t
-->
## 检查网络适配器
如果有一个以上的网络适配器,同时的 Kubernetes 组件通过默认路由不可达,我们建议预先添加 IP 路由规则,这样 Kubernetes 集群就可以通过对应的适配器完成连接。
如果有一个以上的网络适配器,同时的 Kubernetes 组件通过默认路由不可达,我们建议预先添加 IP 路由规则,这样 Kubernetes 集群就可以通过对应的适配器完成连接。
<!--
## Ensure iptables tooling does not use the nftables backend
## Letting iptables see bridged traffic
In Linux, nftables is available as a modern replacement for the kernel's iptables subsystem. The
`iptables` tooling can act as a compatibility layer, behaving like iptables but actually configuring
nftables. This nftables backend is not compatible with the current kubeadm packages: it causes duplicated
firewall rules and breaks `kube-proxy`.
Make sure that the `br_netfilter` module is loaded. This can be done by running `lsmod | grep br_netfilter`. To load it explicitly call `sudo modprobe br_netfilter`.
If your system's `iptables` tooling uses the nftables backend, you will need to switch the `iptables`
tooling to 'legacy' mode to avoid these problems. This is the case on at least Debian 10 (Buster),
Ubuntu 19.04, Fedora 29 and newer releases of these distributions by default. RHEL 8 does not support
switching to legacy mode, and is therefore incompatible with current kubeadm packages.
As a requirement for your Linux Node's iptables to correctly see bridged traffic, you should ensure `net.bridge.bridge-nf-call-iptables` is set to 1 in your `sysctl` config, e.g.
-->
## 确保 iptables 工具不使用 nftables 后端
## 允许 iptables 检查桥接流量
在 Linux 中,nftables 当前可以作为内核 iptables 子系统的替代品。
`iptables` 工具可以充当兼容性层,其行为类似于 iptables 但实际上是在配置 nftables
nftables 后端与当前的 kubeadm 软件包不兼容:它会导致重复防火墙规则并破坏 `kube-proxy`
确保 `br_netfilter` 模块被加载。这一操作可以通过运行 `lsmod | grep br_netfilter`
来完成。若要显式加载该模块,可执行 `sudo modprobe br_netfilter`
如果您系统的 `iptables` 工具使用 nftables 后端,则需要把 `iptables` 工具切换到“旧版”模式来避免这些问题。
默认情况下,至少在 Debian 10 (Buster)、Ubuntu 19.04、Fedora 29 和较新的发行版本中会出现这种问题。RHEL 8 不支持切换到旧版本模式,因此与当前的 kubeadm 软件包不兼容。
为了让你的 Linux 节点上的 iptables 能够正确地查看桥接流量,你需要确保在你的
`sysctl` 配置中将 `net.bridge.bridge-nf-call-iptables` 设置为 1。例如:
{{< tabs name="iptables_legacy" >}}
{{% tab name="Debian 或 Ubuntu" %}}
```bash
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set arptables /usr/sbin/arptables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
```
{{% /tab %}}
{{% tab name="Fedora" %}}
```bash
update-alternatives --set iptables /usr/sbin/iptables-legacy
```
{{% /tab %}}
{{< /tabs >}}
<!--
For more details please see the [Network Plugin Requirements](/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/#network-plugin-requirements) page.
-->
更多的相关细节可查看[网络插件需求](/zh/docs/concepts/extend-kubernetes/compute-storage-net/network-plugins/#network-plugin-requirements)页面。
<!--
## Check required ports
### Control-plane node(s)
| Protocol | Direction | Port Range | Purpose | Used By |
|----------|-----------|------------|-------------------------|---------------------------|
| TCP | Inbound | 6443* | Kubernetes API server | All |
| TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 10251 | kube-scheduler | Self |
| TCP | Inbound | 10252 | kube-controller-manager | Self |
| Protocol | Direction | Port Range | Purpose | Used By |
|------------|------------|------------|-------------------------|-------------------------|
| TCP | Inbound | 6443* | Kubernetes API server | All |
| TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 10251 | kube-scheduler | Self |
| TCP | Inbound | 10252 | kube-controller-manager | Self |
-->
## 检查所需端口{#check-required-ports}
### 控制平面节点
| 协议 | 方向 | 端口范围 | 作用 | 使用者 |
|----------|-----------|------------|-------------------------|---------------------------|
| TCP | 入站 | 6443* | Kubernetes API 服务器 | 所有组件 |
| TCP | 入站 | 2379-2380 | etcd server client API | kube-apiserver, etcd |
| TCP | 入站 | 10250 | Kubelet API | kubelet 自身、控制平面组件 |
| TCP | 入站 | 10251 | kube-scheduler | kube-scheduler 自身 |
| TCP | 入站 | 10252 | kube-controller-manager | kube-controller-manager 自身 |
| 协议 | 方向 | 端口范围 | 作用 | 使用者 |
|----------|--------|------------|-------------------------|------------------------------|
| TCP | 入站 | 6443 | Kubernetes API 服务器 | 所有组件 |
| TCP | 入站 | 2379-2380 | etcd 服务器客户端 API | kube-apiserver, etcd |
| TCP | 入站 | 10250 | Kubelet API | kubelet 自身、控制平面组件 |
| TCP | 入站 | 10251 | kube-scheduler | kube-scheduler 自身 |
| TCP | 入站 | 10252 | kube-controller-manager | kube-controller-manager 自身 |
<!--
### Worker node(s)
| Protocol | Direction | Port Range | Purpose | Used By |
|----------|-----------|-------------|-----------------------|-------------------------|
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 30000-32767 | NodePort Services** | All |
| Protocol | Direction | Port Range | Purpose | Used By |
|------------|------------|-------------|---------------------|-------------------------|
| TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
| TCP | Inbound | 30000-32767 | NodePort Services** | All |
** Default port range for [NodePort Services](/docs/concepts/services-networking/service/).
@@ -177,80 +173,101 @@ documentation for the plugins about what port(s) those need.
-->
### 工作节点
| 协议 | 方向 | 端口范围 | 作用 | 使用者 |
|----------|-----------|-------------|-----------------------|-------------------------|
| TCP | 入站 | 10250 | Kubelet API | kubelet 自身、控制平面组件 |
| TCP | 入站 | 30000-32767 | NodePort 服务** | 所有组件 |
| 协议 | 方向 | 端口范围 | 作用 | 使用者 |
|------|--------|-------------|-------------------|-----------------------------|
| TCP | 入站 | 10250 | Kubelet API | kubelet 自身、控制平面组件 |
| TCP | 入站 | 30000-32767 | NodePort 服务 | 所有组件 |
** [NodePort 服务](/zh/docs/concepts/services-networking/service/) 的默认端口范围。
[NodePort 服务](/zh/docs/concepts/services-networking/service/) 的默认端口范围。
使用 * 标记的任意端口号都可以被覆盖,所以需要保证所定制的端口是开放的。
使用 * 标记的任意端口号都可以被覆盖,所以需要保证所定制的端口是开放的。
虽然控制平面节点已经包含了 etcd 的端口,也可以使用自定义的外部 etcd 集群,或是指定自定义端口。
虽然控制平面节点已经包含了 etcd 的端口,也可以使用自定义的外部 etcd 集群,或是指定自定义端口。
使用的 pod 网络插件 (见下) 也可能需要某些特定端口开启。由于各个 pod 网络插件都有所不同,请参阅他们各自文档中对端口的要求。
使用的 Pod 网络插件 (见下) 也可能需要某些特定端口开启。由于各个 Pod 网络插件都有所不同,
请参阅他们各自文档中对端口的要求。
<!--
## Installing runtime {#installing-runtime}
Since v1.6.0, Kubernetes has enabled the use of CRI, Container Runtime Interface, by default.
Since v1.14.0, kubeadm will try to automatically detect the container runtime on Linux nodes
by scanning through a list of well known domain sockets. The detectable runtimes and the
socket paths, that are used, can be found in the table below.
| Runtime | Domain Socket |
|------------|----------------------------------|
| Docker | /var/run/docker.sock |
| containerd | /run/containerd/containerd.sock |
| CRI-O | /var/run/crio/crio.sock |
If both Docker and containerd are detected together, Docker takes precedence. This is
needed, because Docker 18.09 ships with containerd and both are detectable.
If any other two or more runtimes are detected, kubeadm will exit with an appropriate
error message.
On non-Linux nodes the container runtime used by default is Docker.
If the container runtime of choice is Docker, it is used through the built-in
`dockershim` CRI implementation inside of the `kubelet`.
Other CRI-based runtimes include:
- [containerd](https://github.com/containerd/cri) (CRI plugin built into containerd)
- [cri-o](https://cri-o.io/)
- [frakti](https://github.com/kubernetes/frakti)
Refer to the [CRI installation instructions](/docs/setup/cri) for more information.
To run containers in Pods, Kubernetes uses a
{{< glossary_tooltip term_id="container-runtime" text="container runtime" >}}.
-->
## 安装 runtime{#installing-runtime}
从 v1.6.0 版本起,Kubernetes 开始默认允许使用 CRI(容器运行时接口)。
为了在 Pod 中运行容器,Kubernetes 使用
{{< glossary_tooltip term_id="container-runtime" text="容器运行时(Container Runtime" >}}。
从 v1.14.0 版本起,kubeadm 将通过观察已知的 UNIX 域套接字来自动检测 Linux 节点上的容器运行时。
下表中是可检测到的正在运行的 runtime 和 socket 路径。
{{< tabs name="container-runtimes" >}}
{{% tab name="Linux 节点" %}}
<!--
By default, Kubernetes uses the
{{< glossary_tooltip term_id="cri" text="Container Runtime Interface">}} (CRI)
to interface with your chosen container runtime.
| 运行时 | 域套接字 |
If you don't specify a runtime, kubeadm automatically tries to detect an installed
container runtime by scanning through a list of well known Unix domain sockets.
The following table lists container runtimes and their associated socket paths:
| Runtime | Domain Socket |
|------------|---------------------------------|
| Docker | /var/run/docker.sock |
| containerd | /run/containerd/containerd.sock |
| CRI-O | /var/run/crio/crio.sock |
-->
默认情况下,Kubernetes 使用
{{< glossary_tooltip term_id="cri" text="容器运行时接口(Container Runtime InterfaceCRI" >}}
来与你所选择的容器运行时交互。
如果你不指定运行时,则 kubeadm 会自动尝试检测到系统上已经安装的运行时,
方法是扫描一组众所周知的 Unix 域套接字。
下面的表格列举了一些容器运行时及其对应的套接字路径:
| 运行时 | 域套接字 |
|------------|----------------------------------|
| Docker | /var/run/docker.sock |
| containerd | /run/containerd/containerd.sock |
| CRI-O | /var/run/crio/crio.sock |
如果同时检测到 docker 和 containerd,则优先选择 docker。
这是必然的,因为 docker 18.09 附带了 containerd 并且两者都是可以检测到的。
如果检测到其他两个或多个运行时,kubeadm 将以一个合理的错误信息退出。
<!--
<br />
If both Docker and containerd are detected, Docker takes precedence. This is
needed because Docker 18.09 ships with containerd and both are detectable even if you only
installed Docker.
If any other two or more runtimes are detected, kubeadm exits with an error.
在非 Linux 节点上,默认使用 docker 作为容器 runtime。
The kubelet integrates with Docker through the built-in `dockershim` CRI implementation.
如果选择的容器 runtime 是 docker,则通过内置 `dockershim` CRI 在 `kubelet` 的内部实现其的应用。
See [container runtimes](/docs/setup/production-environment/container-runtimes/)
for more information.
-->
<br/>
如果同时检测到 Docker 和 containerd,则优先选择 Docker。
这是必然的,因为 Docker 18.09 附带了 containerd 并且两者都是可以检测到的,
即使你仅安装了 Docker。
如果检测到其他两个或多个运行时,kubeadm 输出错误信息并退出。
基于 CRI 的其他 runtimes 有:
kubelet 通过内置的 `dockershim` CRI 实现与 Docker 集成。
- [containerd](https://github.com/containerd/cri) containerd 的内置 CRI 插件)
- [cri-o](https://cri-o.io/)
- [frakti](https://github.com/kubernetes/frakti)
参阅[容器运行时](/zh/docs/setup/production-environment/container-runtimes/)
以了解更多信息。
请参考 [CRI 安装指南](/zh/docs/setup/production-environment/container-runtimes/)获取更多信息。
{{% /tab %}}
{{% tab name="其它操作系统" %}}
<!--
By default, kubeadm uses {{< glossary_tooltip term_id="docker" >}} as the container runtime.
The kubelet integrates with Docker through the built-in `dockershim` CRI implementation.
See [container runtimes](/docs/setup/production-environment/container-runtimes/)
for more information.
-->
默认情况下, kubeadm 使用 {{< glossary_tooltip term_id="docker" >}} 作为容器运行时。
kubelet 通过内置的 `dockershim` CRI 实现与 Docker 集成。
参阅[容器运行时](/zh/docs/setup/production-environment/container-runtimes/)
以了解更多信息。
{{% /tab %}}
{{< /tabs >}}
<!--
## Installing kubeadm, kubelet and kubectl
@@ -276,17 +293,19 @@ For information about installing `kubectl`, see [Install and set up kubectl](/do
-->
## 安装 kubeadm、kubelet 和 kubectl
需要在每台机器上安装以下的软件包:
需要在每台机器上安装以下的软件包:
* `kubeadm`:用来初始化集群的指令。
* `kubelet`:在集群中的每个节点上用来启动 pod 和容器等。
* `kubelet`:在集群中的每个节点上用来启动 Pod 和容器等。
* `kubectl`:用来与集群通信的命令行工具。
kubeadm **不能**安装或者管理 `kubelet``kubectl`,所以需要确保它们与通过 kubeadm 安装的控制平面的版本相匹配。
kubeadm **不能**安装或者管理 `kubelet``kubectl`,所以需要
确保它们与通过 kubeadm 安装的控制平面的版本相匹配。
如果不这样做,则存在发生版本偏差的风险,可能会导致一些预料之外的错误和问题。
然而,控制平面与 kubelet 间的相差一个次要版本不一致是支持的,但 kubelet 的版本不可以超过 API 服务器的版本。
然而,控制平面与 kubelet 间的相差一个次要版本不一致是支持的,但 kubelet
的版本不可以超过 API 服务器的版本。
例如,1.7.0 版本的 kubelet 可以完全兼容 1.8.0 版本的 API 服务器,反之则不可以。
有关安装 `kubectl` 的信息,请参阅[安装和设置 kubectl](/zh/docs/tasks/tools/install-kubectl/)文档。
@@ -310,10 +329,11 @@ For more information on version skews, see:
关于版本偏差的更多信息,请参阅以下文档:
* Kubernetes [版本与版本间的偏差策略](/zh/docs/setup/release/version-skew-policy/)
* Kubeadm-specific [版本偏差策略](/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#version-skew-policy)
* Kubeadm 特定的[版本偏差策略](/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#version-skew-policy)
{{< tabs name="k8s_install" >}}
{{% tab name="Ubuntu、Debian 或 HypriotOS" %}}
```bash
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
@@ -324,17 +344,21 @@ sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
```
{{% /tab %}}
{{% tab name="CentOS、RHEL 或 Fedora" %}}
```bash
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
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
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
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
exclude=kubelet kubeadm kubectl
EOF
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
@@ -345,53 +369,58 @@ yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
```
<!--
<!--
**Note:**
- Setting SELinux in permissive mode by running `setenforce 0` and `sed ...` effectively disables it.
This is required to allow containers to access the host filesystem, which is needed by pod networks for example.
You have to do this until SELinux support is improved in the kubelet.
- Some users on RHEL/CentOS 7 have reported issues with traffic being routed incorrectly due to iptables being bypassed. You should ensure
`net.bridge.bridge-nf-call-iptables` is set to 1 in your `sysctl` config, e.g.
```bash
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
```
- Make sure that the `br_netfilter` module is loaded before this step. This can be done by running `lsmod | grep br_netfilter`. To load it explicitly call `modprobe br_netfilter`.
- You can leave SELinux enabled if you know how to configure it but it may require settings that are not supported by kubeadm.
-->
**请注意:**
**请注意:**
- 通过运行命令 `setenforce 0``sed ...` 将 SELinux 设置为 permissive 模式
可以有效地将其禁用。
这是允许容器访问主机文件系统所必需的,而这些操作时为了例如 Pod 网络工作正常。
- 通过运行命令 `setenforce 0` 和 `sed ...` 将 SELinux 设置为 permissive 模式可以有效的将其禁用
这是允许容器访问主机文件系统所必须的,例如正常使用 pod 网络。
您必须这么做,直到 kubelet 做出升级支持 SELinux 为止。
- 一些 RHEL/CentOS 7 的用户曾经遇到过问题:由于 iptables 被绕过而导致流量无法正确路由的问题。您应该确保
在 `sysctl` 配置中的 `net.bridge.bridge-nf-call-iptables` 被设置为 1。
你必须这么做,直到 kubelet 做出对 SELinux 的支持进行升级为止
- 你可以保持 SELinux 处于弃用状态,前提是你知道如何配置它,不过这也意味着有些
配置是 kubeadm 所不支持的。
```bash
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
```
- 确保在此步骤之前已加载了 `br_netfilter` 模块。这可以通过运行 `lsmod | grep br_netfilter` 来完成。要显示加载它,请调用 `modprobe br_netfilter`。
{{% /tab %}}
{{% tab name="Container Linux" %}}
{{% tab name="Fedora CoreOS 或 Flatcar Container Linux" %}}
<!--
Install CNI plugins (required for most pod network):
-->
安装 CNI 插件(大多数 pod 网络都需要):
安装 CNI 插件(大多数 Pod 网络都需要):
```bash
CNI_VERSION="v0.8.2"
mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | sudo tar -C /opt/cni/bin -xz
```
<!--
Define the directory to download command files
-->
定义要下载命令文件的目录。
{{< note >}}
<!--
The DOWNLOAD_DIR variable must be set to a writable directory.
If you are running Flatcar Container Linux, set DOWNLOAD_DIR=/opt/bin.
-->
DOWNLOAD_DIR 变量必须被设置为一个可写入的目录。
如果你在运行 Flatcar Container Linux,可将 DOWNLOAD_DIR 设置为 /opt/bin。
{{< /note >}}
```bash
DOWNLOAD_DIR=/usr/local/bin
sudo mkdir -p $DOWNLOAD_DIR
```
<!--
@@ -400,9 +429,8 @@ Install crictl (required for kubeadm / Kubelet Container Runtime Interface (CRI)
安装 crictlkubeadm/kubelet 容器运行时接口(CRI)所需)
```bash
CRICTL_VERSION="v1.16.0"
mkdir -p /opt/bin
curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | tar -C /opt/bin -xz
CRICTL_VERSION="v1.17.0"
curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-amd64.tar.gz" | sudo tar -C $DOWNLOAD_DIR -xz
```
<!--
@@ -412,12 +440,15 @@ Install `kubeadm`, `kubelet`, `kubectl` and add a `kubelet` systemd service:
```bash
RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
mkdir -p /opt/bin
cd /opt/bin
curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
cd $DOWNLOAD_DIR
sudo curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
chmod +x {kubeadm,kubelet,kubectl}
RELEASE_VERSION="v0.4.0"
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service
sudo mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service
mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" | sed "s:/usr/bin:/opt/bin:g" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
@@ -426,15 +457,27 @@ curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/bu
<!--
Enable and start `kubelet`:
-->
开启并启动 `kubelet`
激活并启动 `kubelet`
```bash
systemctl enable --now kubelet
```
{{< note >}}
<!--
The Flatcar Container Linux distribution mounts the `/usr` directory as a read-only filesystem.
Before bootstrapping your cluster, you need to take additional steps to configure a writable directory.
See the [Kubeadm Troubleshooting guide](/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/#usr-mounted-read-only/) to learn how to set up a writable directory.
-->
Flatcar Container Linux 发行版会将 `/usr/` 目录挂载为一个只读文件系统。
在启动引导你的集群之前,你需要执行一些额外的操作来配置一个可写入的目录。
参见 [kubeadm 故障排查指南](/zh/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/#usr-mounted-read-only/)
以了解如何配置一个可写入的目录。
{{< /note >}}
{{% /tab %}}
{{< /tabs >}}
<!--
The kubelet is now restarting every few seconds, as it waits in a crashloop for
kubeadm to tell it what to do.
@@ -447,53 +490,63 @@ kubelet 现在每隔几秒就会重启,因为它陷入了一个等待 kubeadm
When using Docker, kubeadm will automatically detect the cgroup driver for the kubelet
and set it in the `/var/lib/kubelet/kubeadm-flags.env` file during runtime.
If you are using a different CRI, you have to modify the file
`/etc/default/kubelet` (`/etc/sysconfig/kubelet` for CentOS, RHEL, Fedora) with your `cgroup-driver` value, like so:
If you are using a different CRI, you must pass your `cgroupDriver` value to `kubeadm init`, like so:
-->
## 在控制平面节点上配置 kubelet 使用的 cgroup 驱动程序 {#configure-cgroup-driver-used-by-kubelet-on-contol-plane-node}
```bash
KUBELET_EXTRA_ARGS=--cgroup-driver=<value>
使用 Docker 时,kubeadm 会自动为其检测 cgroup 驱动并在运行时对
`/var/lib/kubelet/kubeadm-flags.env` 文件进行配置。
如果你在使用不同的 CRI,你必须为 `kubeadm init` 传递 `cgroupDriver`
值,像这样:
```yaml
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: <value>
```
This file will be used by `kubeadm init` and `kubeadm join` to source extra
user defined arguments for the kubelet.
<!--
For further details, please read [Using kubeadm init with a configuration file](/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file).
Please mind, that you **only** have to do that if the cgroup driver of your CRI
is not `cgroupfs`, because that is the default value in the kubelet already.
-->
进一步的相关细节,可参阅
[使用配置文件来执行 kubeadm init](/zh/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file)。
请注意,你只需要在你的 cgroup 驱动程序不是 `cgroupfs` 时这么做,
因为它已经是 kubelet 中的默认值。
{{< note >}}
<!--
Since `--cgroup-driver` flag has been deprecated by the kubelet, if you have that in `/var/lib/kubelet/kubeadm-flags.env`
or `/etc/default/kubelet`(`/etc/sysconfig/kubelet` for RPMs), please remove it and use the KubeletConfiguration instead
(stored in `/var/lib/kubelet/config.yaml` by default).
-->
由于 kubelet 已经弃用了 `--cgroup-driver` 标志,如果你在配置文件
`/var/lib/kubelet/kubeadm-flags.env` 或者 `/etc/default/kubelet`
(对于 RPM 而言是 `/etc/sysconfig/kubelet`)包含此设置,请将其删除
并使用 KubeletConfiguration 作为替代(默认存储于
`/var/lib/kubelet/config.yaml` 文件中)。
{{< /note >}}
<!--
Restarting the kubelet is required:
-->
需要重新启动 kubelet
```bash
sudo systemctl daemon-reload
sudo systemctl restart kubelet
```
<!--
The automatic detection of cgroup driver for other container runtimes
like CRI-O and containerd is work in progress.
-->
## 在控制平面节点上配置 kubelet 使用的 cgroup 驱动程序 {#configure-cgroup-driver-used-by-kubelet-on-master-node}
使用 docker 时,kubeadm 会自动为其检测 cgroup 驱动并在运行时对 `/var/lib/kubelet/kubeadm-flags.env` 文件进行配置。
如果您使用不同的 CRI,您需要使用 `cgroup-driver` 值修改 `/etc/default/kubelet` 文件(对于 CentOS、RHEL、Fedora,修改 `/etc/sysconfig/kubelet` 文件),像这样:
```bash
KUBELET_EXTRA_ARGS=--cgroup-driver=<value>
```
这个文件将由 `kubeadm init` 和 `kubeadm join` 使用以获取额外的用户自定义的 kubelet 参数。
请注意,您 **只** 需要在您的 cgroup 驱动程序不是 `cgroupfs` 时这么做,因为它已经是 kubelet 中的默认值。
需要重新启动 kubelet
```bash
systemctl daemon-reload
systemctl restart kubelet
```
自动检测其他容器运行时的 cgroup 驱动,例如在进程中工作的 CRI-O 和 containerd。
自动检测其他容器运行时(例如 CRI-O 和 containerd)的 cgroup 驱动的相关
工作扔在进行中。
<!--
## Troubleshooting
@@ -502,12 +555,11 @@ If you are running into difficulties with kubeadm, please consult our [troublesh
-->
## 故障排查
如果在使用 kubeadm 时遇到困难,请参阅我们的
如果在使用 kubeadm 时遇到困难,请参阅我们的
[故障排查文档](/zh/docs/setup/production-environment/tools/kubeadm/troubleshooting-kubeadm/)。
## {{% heading "whatsnext" %}}
<!--
* [Using kubeadm to Create a Cluster](/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/)
-->