2023-09-12 22:58:49 +08:00
#!/bin/bash
source cluster.env
if [ $( id -u) != "0" ] ; then
echo "Error: You must be root to run this script"
exit 1
fi
2024-01-30 16:19:24 +08:00
# 部署之前先分发 init 内容
scp -r init/ root@${ MASTER1 } :/tmp/
scp -r init/ root@${ MASTER2 } :/tmp/
scp -r init/ root@${ MASTER3 } :/tmp/
2024-01-30 16:42:11 +08:00
ssh root@${ MASTER1 } "cd /tmp/init/ && bash ./init.sh"
ssh root@${ MASTER2 } "cd /tmp/init/ && bash ./init.sh"
ssh root@${ MASTER3 } "cd /tmp/init/ && bash ./init.sh"
2023-09-13 10:45:29 +08:00
# 生成keepalived配置文件
2023-09-13 14:57:41 +08:00
git checkout keepalived/*.conf
2023-09-13 10:45:29 +08:00
sed -e " s/__MASTER1__/ ${ MASTER1 } /g " \
-e " s/__MASTER2__/ ${ MASTER2 } /g " \
-e " s/__MASTER3__/ ${ MASTER3 } /g " \
2023-09-13 14:57:41 +08:00
-e " s/__VIP__/ ${ API_SERVER } /g " \
2023-09-13 10:45:29 +08:00
-e " s/__NETWORK_NIC__/ ${ NETWORK_NIC } /g " \
-i keepalived/*.conf
# 分发仓库文件
2023-09-13 23:01:30 +08:00
rsync -avz --exclude= temp * root@${ MASTER1 } :/tmp/
rsync -avz --exclude= temp * root@${ MASTER2 } :/tmp/
rsync -avz --exclude= temp * root@${ MASTER3 } :/tmp/
2023-09-13 10:45:29 +08:00
2023-09-13 14:57:41 +08:00
# keepalived 配置
ssh root@${ MASTER1 } "cd /tmp/keepalived/ && bash install.sh && cp -r keepalived1.conf /etc/keepalived/keepalived.conf && systemctl restart keepalived"
ssh root@${ MASTER2 } "cd /tmp/keepalived/ && bash install.sh && cp -r keepalived2.conf /etc/keepalived/keepalived.conf && systemctl restart keepalived"
ssh root@${ MASTER3 } "cd /tmp/keepalived/ && bash install.sh && cp -r keepalived3.conf /etc/keepalived/keepalived.conf && systemctl restart keepalived"
2024-01-31 08:20:42 +08:00
# 安装Docker
ssh root@${ MASTER1 } "cd /tmp/docker/ && bash ./install.sh"
ssh root@${ MASTER2 } "cd /tmp/docker/ && bash ./install.sh"
ssh root@${ MASTER3 } "cd /tmp/docker/ && bash ./install.sh"
2024-01-30 18:09:22 +08:00
# 安装 kubeadm 组件
ssh root@${ MASTER1 } "cd /tmp/kubeadm/ && bash install.sh"
ssh root@${ MASTER2 } "cd /tmp/kubeadm/ && bash install.sh"
ssh root@${ MASTER3 } "cd /tmp/kubeadm/ && bash install.sh"
2023-09-13 14:57:41 +08:00
# 创建集群
2024-01-30 15:56:17 +08:00
cd kubeadm
2023-09-13 14:57:41 +08:00
./create_cluster.sh ${ API_SERVER } | tee /tmp/install.log
# 获取安装信息
MASTER_JOIN_COMMAND = $( cat /tmp/install.log | grep -A 5 "You can now join any number of the control-plane" | grep -vE " You can now join any number of the control-plane|^ $" )
ssh root@${ MASTER2 } " ${ MASTER_JOIN_COMMAND } "
ssh root@${ MASTER3 } " ${ MASTER_JOIN_COMMAND } "