Debian 12 部署 k8s
准备
服务器配置
三台服务器,每台服务器内存2GB或更多,CPU2核或更多,硬盘30GB或更多
服务器设置
ip | hostname | role |
---|---|---|
10.211.55.15 | node15 | master |
10.211.55.16 | node16 | worker |
10.211.55.17 | node17 | worker |
hostnamectl set-hostname node15
hostnamectl set-hostname node16
hostnamectl set-hostname node17
cat << EOF > /etc/hosts
10.211.55.15 node15
10.211.55.16 node16
10.211.55.17 node17
EOF
禁用selinux
服务器如果启用了 selinux
则禁用 selinux
:
setenforce 0
vi /etc/selinux/config
将文件中 SELINUX 改为 disable:SELINUX=disabled
开机自动加载内核模块
系统启动时自动加载所需的内核模块,以满足容器运行时的要求:
cat << EOF > /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
使以上配置生效
modprobe overlay
modprobe br_netfilter
创建/etc/sysctl.d/99-kubernetes-cri.conf配置文件:
cat << EOF > /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
user.max_user_namespaces=28633
EOF
使以上配置生效
sysctl -p /etc/sysctl.d/99-kubernetes-cri.conf
服务器支持ipvs
cat > /etc/modules-load.d/ipvs.conf <<EOF
ip_vs
ip_vs_rr
ip_vs_wrr
ip_vs_sh
EOF
使以上配置立即生效:
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
安装ipset
和ipvsadm
apt install -y ipset ipvsadm
部署 K8S
部署容器运行时Containerd
wget https://github.com/containerd/containerd/releases/download/v1.7.11/containerd-1.7.11-linux-amd64.tar.gz
tar Cxzvf /usr/local containerd-1.7.11-linux-amd64.tar.gz
安装runc
wget https://github.com/opencontainers/runc/releases/download/v1.1.9/runc.amd64
install -m 755 runc.amd64 /usr/local/sbin/runc
生成containerd
的配置文件:
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
将文件/etc/containerd/config.toml
中的SystemdCgroup
配置改为true
,sandbox_image
改为registry.aliyuncs.com/google_containers/pause:3.9
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri"]
...
# sandbox_image = "registry.k8s.io/pause:3.8"
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
为了通过systemd
启动containerd
,需要从 https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
下载containerd.service
文件,并将其放置在/etc/systemd/system/containerd.service
中。
cat << EOF > /etc/systemd/system/containerd.service
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target local-fs.target
[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/containerd
Type=notify
Delegate=yes
KillMode=process
Restart=always
RestartSec=5
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
OOMScoreAdjust=-999
[Install]
WantedBy=multi-user.target
EOF
配置containerd
开机启动,并启动containerd
:
systemctl daemon-reload
systemctl enable containerd --now
systemctl status containerd
下载安装crictl
工具
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.29.0/crictl-v1.29.0-linux-amd64.tar.gz
tar -zxvf crictl-v1.29.0-linux-amd64.tar.gz
install -m 755 crictl /usr/local/bin/crictl
测试是否安装成功:
crictl --runtime-endpoint=unix:///run/containerd/containerd.sock version
输出:
Version: 0.1.0
RuntimeName: containerd
RuntimeVersion: v1.7.11
RuntimeApiVersion: v1