安装环境准备
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
关闭swap
sed -ri 's/.*swap.*/#&/' /etc/fstab
将桥接的 IPv4 流量传递到 iptables 的链
cat <<EOF >>/etc/sysctl.conf
> net.bridge.bridge-nf-call-iptables = 1
> net.bridge.bridge-nf-call-ip6tables = 1
> EOF
sysctl --system
设置主机名字
hostnamectl set-hostname k8smaster
hostnamectl set-hostname k8snode1
hostnamectl set-hostname k8snode2
在master添加hosts
cat <<EOF >>/etc/hosts
> 192.168.184.151 k8smaster
> 192.168.184.152 k8snode1
> 192.168.184.153 k8snode2
> EOF
安装docker
安装完成后修改Cgroup Driver
/etc/docker/daemon.json
新增
"exec-opts": ["native.cgroupdriver=systemd"]
systemctl daemon-reload
systemctl restart docker
安装 kubeadm、kubelet 和 kubectl
阿里云镜像
yum install -y --nogpgcheck kubelet-1.22.5 kubeadm-1.22.5 kubectl-1.22.5
systemctl enable kubelet && systemctl start kubelet
安装需要的镜像
kubeadm config images list --kubernetes-version v1.22.5
k8s.gcr.io/kube-apiserver:v1.22.5
k8s.gcr.io/kube-controller-manager:v1.22.5
k8s.gcr.io/kube-scheduler:v1.22.5
k8s.gcr.io/kube-proxy:v1.22.5
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4
用kubeadm来初始化集群(仅master节点执行)
kubeadm init \
--apiserver-advertise-address=192.168.184.151 \
--kubernetes-version v1.22.5 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all
如果出现
Your Kubernetes control-plane has initialized successfully!
说明初始化成功
会得到一段kubeadm join node节点用来加入master
根据提示
node节点用来加入master后
通过kubectl get nodes查看节点
节点都是NotReady,需要安装一个网络插件,他们才能工作