offline-kubernetes-install/scripts/2-create_k8s.sh

29 lines
700 B
Bash
Raw Normal View History

2023-04-26 19:57:49 +08:00
#!/bin/bash
2023-09-12 17:28:07 +08:00
set -euo pipefail
2023-09-12 17:20:40 +08:00
apiserver="__API_SERVER__"
2023-04-26 19:57:49 +08:00
2023-09-12 22:55:48 +08:00
# 初始化集群
2023-04-26 19:57:49 +08:00
sudo kubeadm init \
--kubernetes-version 1.21.10 \
--control-plane-endpoint "${apiserver}:6443" \
--upload-certs \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
2023-09-12 22:55:48 +08:00
# 配置kubeconfig
2023-04-26 19:57:49 +08:00
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
2023-09-12 22:55:48 +08:00
# kubectl自动补全
2023-04-26 19:57:49 +08:00
if [ $(grep -c "kubectl completion bash" /root/.bashrc) -eq 0 ];then
cat <<EOF | sudo tee -a /root/.bashrc
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
EOF
fi
2023-09-12 22:55:48 +08:00
# 安装flannel
2023-09-12 17:40:05 +08:00
cd ../flannel && bash install.sh && cd -