系统相关
首页 > 系统相关> > centos8 kubernetes k8s v1.22.1 搭配containerd搭建集群

centos8 kubernetes k8s v1.22.1 搭配containerd搭建集群

作者:互联网

系统环境配置

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

#关闭selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
setenforce 0

#关闭swap
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

#同步服务器时间
timedatectl set-timezone Asia/Shanghai
yum install chrony -y 
systemctl enable chronyd 
systemctl start chronyd 
chronyc sources

#配置网络转发
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

net.ipv4.ip_forward = 1
EOF

#加载配置生效
modprobe br_netfilter 
sysctl -p /etc/sysctl.d/k8s.conf 

安装containerd

wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install containerd -y

#创建目录并生成配置文件
mkdir -p /etc/containerd 
containerd config default > /etc/containerd/config.toml 
# 替换配置文件,设置阿里云加速仓库,启用systemd管理cgroup
sed -i "s#k8s.gcr.io#registry.cn-hangzhou.aliyuncs.com/google_containers#g"  /etc/containerd/config.toml 
sed -i '/containerd.runtimes.runc.options/a\ \ \ \ \ \ \ \ \ \ \ \ SystemdCgroup = true' /etc/containerd/config.toml 
sed -i "s#https://registry-1.docker.io#https://bncakk5o.mirror.aliyuncs.com#g"  /etc/containerd/config.toml 

#启动containerd
systemctl daemon-reload 
systemctl enable containerd 
systemctl restart containerd 

安装k8s

cat > /etc/yum.repos.d/kubernetes.repo <<EOF 
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet-1.22.1 kubeadm-1.22.1 kubectl-1.22.1

#设置运行时
crictl config runtime-endpoint /run/containerd/containerd.sock

#设置为开机启动kubelet
systemctl daemon-reload 
systemctl enable kubelet && systemctl restart kubelet

#初始化集群
kubeadm init \
--apiserver-advertise-address=192.168.56.108 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.22.1 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.50.0.0/16 \
--cri-socket=

#初始化完成后会再末尾生成提示,按照下列提示操作,将kubeadm join复制到其他node节点执行即可。

To start using your cluster, you need to run the following as a regular user: 
 
  mkdir -p $HOME/.kube 
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config 
  sudo chown $(id -u):$(id -g) $HOME/.kube/config 
 
Alternatively, if you are the root user, you can run: 
 
  export KUBECONFIG=/etc/kubernetes/admin.conf 
 
You should now deploy a pod network to the cluster. 
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: 
  https://kubernetes.io/docs/concepts/cluster-administration/addons/ 
 
Then you can join any number of worker nodes by running the following on each as root: 
 
kubeadm join 192.168.56.108:6443 --token v5u33x.o9x2p89x2e5x659n \
	--discovery-token-ca-cert-hash sha256:c704c9c42840b0bf27f1c91681cc9dabb4d0e67ba2a0ac557009b9a31961a87b

其他node节点除了不用初始化init,其他配置均一致。

节点加入后,会处于notready状态,是因为没有安装网络插件,这里安装calico,执行下列命令即可

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

标签:sed,kubernetes,containerd,etc,v1.22,systemctl,toml,config
来源: https://www.cnblogs.com/wayne91/p/15438275.html