环境参数:
- 系统:ubuntu20.04
- k8s:1.25.3
- 容器运行时:containerd
关闭防火墙
sudo ufw disable
关闭swap
临时关闭:
swapoff -a
永久关闭:
sed -i '/ swap / s/^/#/' /etc/fstab
关闭之后,使用top命令查看swap分区的情况
时间同步(使用chrony)
apt -y install chrony
chronyc sources -v
内核参数调整
使用docker会自动配置,但使用containerd需手动配置。
允许iptables检查桥接流量,若要显式加载此模块,需运行 modprobe br_netfilter
为了让Linux节点的 iptables 能够正确的查看桥接流量,还需要确认 net.bridge.bridge-nf-call-iptables 设置为 1
# 加载模块
modprobe overlay
modprobe br_netfilter
# 开机加载
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
设置所需的 sysctl 参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
应用 sysctl 参数而不重新启动
sysctl --system
下载docker.io(optional)
sudo apt update
sudo apt -y install docker.io
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://docker.mirrors.ustc.edu.cn",
"https://hub-mirror.c.163.com",
"https://reg-mirror.qiniu.com",
"https://registry.docker-cn.com"
],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl restart docker.service
# 验证是否成功
docker info | grep Cgroup
下载containerd(optional)
sudo apt update
sudo apt -y install containerd
systemctl status containerd
containerd --version
ctr version
sudo mkdir /etc/containerd
containerd config default > /etc/containerd/config.toml
要在国内使用,需更换镜像源
grep sandbox_image /etc/containerd/config.toml
命令打出来是 sandbox_image = 'registry.k8s.io/pause'
,这个源国内无法使用,更换为阿里源:
sudo sed -i "s#registry.k8s.io/pause#registry.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml
修改完重启containerd服务
systemctl restart containerd
安装kubeadm kubectl kubelet
首先添加gpg证书
sudo apt update && sudo apt install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
sudo apt update
安装
# 安装指定版本
sudo apt install -y kubeadm=1.25.0-00 kubelet=1.25.0-00 kubectl=1.25.0-00
# 安装最新版本
sudo apt install -y kubelet kubeadm kubectl
安装cri-dockerd(optional)
curl -LO https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.6/cri-dockerd_0.2.6.3-0.ubuntu-focal_amd64.deb
修改如下配置
vim /lib/systemd/system/cri-docker.service
ExecStart=/usr/bin/cri-dockerd --container-runtime-endpoint fd:// --pod-infra-container-image registry.aliyuncs.com/google_containers/pause:3.7
重启服务
systemctl daemon-reload && systemctl restart cri-docker.service
初始化集群
kubeadm init \
--apiserver-advertise-address=192.168.48.200 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=v1.25.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--token-ttl=0 \
--cri-socket unix:///run/cri-dockerd.sock
标签:cri,--,containerd,sudo,环境,apt,etc,K8S,搭建
From: https://www.cnblogs.com/xdaniel/p/16954269.html