一、準備環境(所有伺服器)
1.各伺服器設定hosts
192.168.137.100 k8s-master
192.168.137.101 k8s-node1
192.168.137.102 k8s-node2
hostname set-hostname k8s-master
hostname set-hostname k8s-node1
hostname set-hostname k8s-node1
2。時間同步
自己想辦法
3.lvs環境(暫定)
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
4.vim /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness =0
5.清除iptables
iptable -F ; iptables -t nat -F
6.修改 vim /run/systemd/resolve/resolv.conf(非常重要)
nameserver 10.96.0.1
7.基礎環境一定要配置齊全
8.安裝驅動
modprobe br_netfilter
modprobe overlay
二、準備軟體(所有伺服器)
1.在離線的環境下準備好需要的服務依賴映象,需要從docker打包下載。
calico/kube-controllers v3.27.3
calico/cni v3.27.3
calico/pod2daemon-flexvol v3.27.3
calico/node v3.27.3
registry.aliyuncs.com/google_containers/kube-apiserver v1.28.2
registry.aliyuncs.com/google_containers/kube-scheduler v1.28.2
registry.aliyuncs.com/google_containers/kube-proxy v1.28.2
registry.aliyuncs.com/google_containers/kube-controller-manager v1.28.2
registry.aliyuncs.com/google_containers/etcd 3.5.9-0
registry.aliyuncs.com/google_containers/coredns v1.10.1
registry.aliyuncs.com/google_containers/pause 3.9
2.匯入映象到ctr管理
ctr -n k8s.io images import kube-controllers.tar.gz
所有的服務全部匯入
列出所有的映象
ctr -n k8s.io images ls
三、部署docker-ce,docker-ce-cli、containerd.io (所有伺服器)
1.在有網的環境下載好所有的軟體
sudo apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances 修改這裡為包名| grep "^\w" | sort -u)
隨後執行dpkg -i *.deb安裝軟體
隨後檢視狀態
systemctl status docker
systemctl status containerd
systemctl status docker.socket
配置contanerd
containerd config default > /etc/containerd/config.toml
sed -i '/SystemdCgroup/s/false/true/g' /etc/containerd/config.toml
sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
systemctl enable containerd
systemctl start containerd
四、部署k8s
1.在離線環境下載好所有的離線軟體(kubectl、kubeadmi、kubelet)更具上面的操作執行
kubeadm init --apiserver-advertise-address=192.168.137.100 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.28.2 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.0.0.0/16 --ignore-preflight-errors=all --cri-socket /run/containerd/containerd.sock
會出現報錯,執行一下重新初始化
重新打一下etcd的tag
mkdir -p $HOME/.kube sudo
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf(這句話要寫進環境變數)
客戶端根據自己的輸出執行已下操作;
kubeadm join 192.168.137.100:6443 --token 5zuk01.90lzu02xkdcyb3w2 --discovery-token-ca-cert-hash sha256:5cd777c253f3f99e0193e61e4b8c54f2910bc956435b13136e5e0f07f06a04c2
2.加入網路外掛
修改calico.yaml
- name: CALICO_IPV4POOL_CIDR
value: "10.0.0.0/16"
- name: IP_AUTODETECTION_METHOD
value: "interface=ens33"
kubectl apply -f calico.yaml 生效配置
五、驗證是否完成