k8s-deploy/control-plane-install.sh.j2
2025-11-21 15:21:45 +08:00

42 lines
1.2 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
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 "控制平面安装完成。"