1、准备服务器

ip: 172.22.21.20,172.22.21.21,172.22.21.22

2、关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

3、关闭swap分区

swapoff -a     # 临时
vim /etc/fstab # 永久, 注释掉swap那一行

4、关闭selinux

setenforce 0                                        # 临时
sed -i 's/enforcing/disabled/' /etc/selinux/config  # 永久

5、配置hosts

cat >> /etc/hosts << EOF
172.22.21.20 master
172.22.21.21 slaver01
172.22.21.22 slaver02
EOF

6、修改iptables

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter


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 --system

7、安装docker

yum install -y yum-utils   device-mapper-persistent-data   lvm2
yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io
systemctl start docker	# 启动 docker服务

systemctl enable docker # 设置开机启动 docker

8、修改镜像源并禁掉cgroup

mkdir -p /etc/docker

cd /etc/docker && vim daemon.json

# 修改文件
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}

9、启动并配置docker自启动

systemctl restart docker
docker --version
docker info

10、安装cri-docker、

10.1 下载rpm

https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.6/cri-dockerd-0.2.6-3.el7.x86_64.rpm

10.2 安装cri-dockerd

rpm -ivh cri-dockerd-0.2.6-3.el7.x86_64.rpm

10.3 修改service文件

vim /usr/lib/systemd/system/cri-docker.service
ExecStart=/usr/bin/cri-dockerd --network-plugin=cni --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.8 --container-runtime-endpoint

10.4 启动cri-docker

systemctl start cri-docker && systemctl enable cri-docker

11、安装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=0
repo_gpgcheck=0
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.25.2 kubeadm-1.25.2 kubectl-1.25.2
systemctl enable kubelet

12、部署master节点

kubeadm reset --cri-socket=unix:///var/run/cri-dockerd.sock

kubeadm init \
--apiserver-advertise-address=172.22.21.20 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.2 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
--cri-socket unix:///var/run/cri-dockerd.sock

export KUBECONFIG=/etc/kubernetes/admin.conf

# 安装 Pod 网络插件(CNI) 
wget https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f calico.yaml

13、其他节点加入集群

kubeadm join 172.22.21.20:6443 --token 5r5fib.00mlurgn42d0jfo4 --discovery-token-ca-cert-hash sha256:a82b499d9d6dd54bace49998bea48de68a17f312eb4752ab694680502c2befce --cri-socket=unix:///var/run/cri-docerd.sock

14、如果想master节点可以部署pod的话,需要执行下面命令

kubectl taint nodes --all node-role.kubernetes.io/control-plane-

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐