shenmingbusujiku / Linux

关于Linux的学习和项目
0 stars 0 forks source link

集群部署 #22

Open shenmingbusujiku opened 2 years ago

shenmingbusujiku commented 2 years ago

环境准备

在所有机器上关闭防火墙 在所有机器上关闭selinux 在所有机器上关闭swap swapoff -a # 临时关闭 sed -ri 's/.swap./#&/' /etc/fstab #永久关闭 修改主机名 在所有机器上添加域名解析 在所有机器上将桥接的ipv4流量传递到iptables的链 vim /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1

为所有节点安装docker

yum install wget.x86_64 -y rm -rf /etc/yum.repos.d/* wget -O /etc/yum.repos.d/centos7.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum install docker-ce -y

集群部署

配置镜像仓库,https://developer.aliyun.com/mirror/kubernetes?spm=a2c6h.13651102.0.0.3e221b 11tmy01T 1.为所有节点修改仓库,安装kubeadm、kubelet、kubectl vim /etc/yum.repos.d/kubernetes.repo [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 yum install -y kubelet kubeadm kubectl (失败用yum install -y --nogpgcheck kubelet kubeadm kubectl) systemctl enable kubelet && systemctl start kubelet 2.修改docker配置 vim /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"] } systemctl daemon-reload systemctl restart docker.service systemctl restart kubelet.service

部署master

kubeadm init \ --apiserver-advertise-address=192.168.80.100 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.22.2 \ --control-plane-endpoint k8s-master1 \ --service-cidr=172.16.0.0/16 \ --pod-network-cidr=10.244.0.0/16

遇到镜像下载问题可以单独下载,

docker pull registry.aliyuncs.com/google_containers/coredns:1.8.4 docker tag registry.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4

按照指示执行

安装网络插件,官方文档:https://github.com/flannel-io/flannel

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml kubectl apply -f kube-flannel.yml

最好手动提前拉取所需镜像

docker pull quay.io/coreos/flannel:v0.14.0

添加node节点

docker pull quay.io/coreos/flannel:v0.14.0 kubeadm join k8s-master1:6443 --token 0re1oq.he6o0ab4mqtjtg83 --discovery-token-ca-cert-hash sha256:460d740c21fa040f7f12e22cdd018aec8c903d4880f42b0f7edeb78a80241b56(在安装时有提示)