k8s-deploy/control-plane-install.sh.j2
2025-11-21 17:55:04 +08:00

65 lines
1.8 KiB
Django/Jinja
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
OFFLINE=/opt/k8s-offline
echo "[1] 解压离线包"
mkdir -p $OFFLINE
tar xf k8s-offline.tgz -C $OFFLINE
tar zxvf $OFFLINE/offlien-cache/deps/crictl-v1.29.0-linux-amd64.tar.gz -C /usr/local/bin
dpkg -i $OFFLINE/offlien-cache/deps/*.deb
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
systemctl enable --now containerd
systemctl status containerd
# 加载模块
modprobe br_netfilter
echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf
# 设置网络转发与桥接
cat <<EOF > /etc/sysctl.d/99-kubernetes.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
echo "[2] 安装 kubeadm/kubelet/kubectl"
install -m755 $OFFLINE/offline-cache/bin/* /usr/local/bin/
echo "[3] 初始化控制平面"
kubeadm init \
--kubernetes-version={{ kubernetes.version }} \
--pod-network-cidr={{ kubernetes.pod_cidr }} \
--service-cidr={{ kubernetes.service_cidr }} \
--upload-certs
mkdir -p ~/.kube
cp /etc/kubernetes/admin.conf ~/.kube/config
echo "[4] 加载所有离线镜像"
for img in $OFFLINE/offline-cache/images/*.tar; do
ctr -n=k8s.io images import "$img"
done
echo "[5] 部署 CNIflannel"
kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml
echo "[6] 部署 KubeVirt 与 CDI"
kubectl apply -f $OFFLINE/offline-cache/manifests/kubevirt-operator.yaml
kubectl apply -f $OFFLINE/offline-cache/manifests/kubevirt-cr.yaml
kubectl apply -f $OFFLINE/offline-cache/manifests/cdi-operator.yaml
kubectl apply -f $OFFLINE/offline-cache/manifests/cdi-cr.yaml
echo "[7] 部署 NFS-CSI"
kubectl apply -f $OFFLINE/offline-cache/manifests/nfs-csi.yaml
echo "控制平面安装完成。"