注意:以下命令都是在 root 下执行的

安装容器运行时

推荐安装 containerd,debian 系列apt install containerd,其他系统自行 google 安装方法。

安装 CNI 网络插件

CNI_PLUGINS_VERSION="v1.1.1"
ARCH="amd64"
DEST="/opt/cni/bin"
mkdir -p "$DEST"
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_PLUGINS_VERSION}/cni-plugins-linux-${ARCH}-${CNI_PLUGINS_VERSION}.tgz" | tar -C "$DEST" -xz

安装 crictl

DOWNLOAD_DIR="/usr/local/bin"
mkdir -p "$DOWNLOAD_DIR"

CRICTL_VERSION="v1.25.0"
ARCH="amd64"
curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" | tar -C $DOWNLOAD_DIR -xz

安装 kubectl,kubeadm,kubelet

kubectl 安装方式见上一篇

RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
ARCH="amd64"
cd $DOWNLOAD_DIR
curl -L --remote-name-all https://dl.k8s.io/release/${RELEASE}/bin/linux/${ARCH}/{kubeadm,kubelet}
chmod +x {kubeadm,kubelet}

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" | tee /etc/systemd/system/kubelet.service
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" | tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

systemctl enable --now kubelet

创建集群

安装主控节点

执行kubeadm init

  • 如果提升缺少某个软件依赖,直接用包管理器安装对应的即可

  • 如果提示/proc/sys/net/bridge/bridge-nf-call-iptables does not exist或者/proc/sys/net/ipv4/ip_forward contents are not set to 1,执行如下命令修复

modprobe br_netfilter
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/ipv4/ip_forward
  • 如果 kubeadm init 时报错 unknown service runtime.v1alpha2.RuntimeService 执行如下命令
mv /etc/containerd/config.toml /root/config.toml.bak
systemctl restart containerd

正常情况下,执行完毕后会输出如下内容:

kubeadm join 192.168.2.246:6443 --token 9jg2hb.77qou6yj0eibam56 \
        --discovery-token-ca-cert-hash sha256:7efa8bd0c5039a1adca6d5888487c0f92cc62fe5d568b0b9c4ba40be4dc4638f

安装工作节点

在另外一台机器上重复执行安装容器运行时,安装 CNI 网络,安装 crictl,安装 kubeadm,kubelet

然后执行上一步kubeadm init输出的命令,加入到集群中