kebuadm 搭建k8s v1.18
1、服务器准备
修改主机名,写入三台主机/etc/hosts
192.168.31.179 k8s-master
192.168.31.180 k8s-node1
192.168.31.181 k8s-node2
关闭防火墙和selinux
systemctl disable firewalld && systemctl stop firewalld
sed -i 's/enforcing/disabled/' /etc/selinux/conf && setenforce 0
修改为阿里云镜像
cat <<EOF > /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
EOF
解除网络限制
cat <<EOF>> /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
2、组件安装
yum -y install docker kubelet kubectl kubeadm
kubelet 代理服务
kubectl 管理
kubeadm 部署
3、集群初始化
在主节点执行
kubeadm init --apiserver-advertise-address=192.168.31.179 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.18.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
--apiserver-advertise-address 主节点IP
--image-repository 镜像源
--pod-network-cidr=10.244.0.0/16 请与flannel网络插件保持一致(flannel网络插件默认为10.244.0.0/16)
根据提示完成初始化步骤
4、加入节点
主节点执行 kubeadm token create --print--join--command
得到kubeadm join 192.168.31.179:6443 --token qzwubw.bumwc63v5lreao8b --discovery-token-ca-cert-hash sha256:a67d7d346ecdf72b68914eddd3581535ad60f97648b23093810e8d5a99afbba2
在其余节点执行
5、网络插件flannel部署
下载部署文件
wget -P k8s/ https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
修改文件
sed -i 's/quay.io/quay-mirror.qiniu.com/g' k8s/kube-flannel.yml
部署
kubectl apply -f k8s/kube-flannel.yml