You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
5.3 KiB
182 lines
5.3 KiB
#!/bin/bash
|
|
#microk8s v1.22.2
|
|
|
|
sudo snap ack ./microk8s离线包/microk8s_2551.assert
|
|
sudo snap install ./microk8s离线包/microk8s_2551.snap --classic
|
|
|
|
if [ $? != 0 ]; then
|
|
echo "------1-- microk8s 安装失败 code=$?---------"
|
|
echo "------1-- microk8s 准备退出 ---------"
|
|
exit 0
|
|
fi
|
|
|
|
microk8s.kubectl create namespace lk
|
|
|
|
dashboardAndCalicoImages_path="./dashboardAndCalicoImages.tar"
|
|
if [ ! -f "$dashboardAndCalicoImages_path" ]; then
|
|
echo "---------$dashboardAndCalicoImages_path dashboard组件包不存在,退出安装"
|
|
exit 0
|
|
fi
|
|
|
|
echo "准备导入 dashboard 组件 镜像"
|
|
microk8s.ctr --namespace k8s.io image import "$dashboardAndCalicoImages_path"
|
|
|
|
|
|
sleep 5s
|
|
|
|
echo "------2-- 组件 准备启动 (这步耗时较久,请等待)---------"
|
|
microk8s status --wait-ready && microk8s enable dashboard
|
|
|
|
token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
|
|
microk8s kubectl -n kube-system describe secret $token >dashboard_token.txt
|
|
|
|
sleep 5s
|
|
|
|
microk8s enable dns
|
|
|
|
echo "------2-- 组件 启动完成 ---------"
|
|
|
|
echo "-------- 本地化 基础进程 开始拉取 ---------"
|
|
|
|
#es 挂载数据路径
|
|
mkdir -p /home/anxinlocal/esdata
|
|
chmod 777 /home/anxinlocal/esdata
|
|
#webapi 报表模板路径
|
|
mkdir -p /home/anxinlocal/static
|
|
#pg 挂载数据路径
|
|
mkdir -p /home/anxinlocal/pgdata
|
|
|
|
#-----------------------------------base----------------------------
|
|
#判断tar 目录是否存在
|
|
baseImages_tarDir="./baseImage_tars"
|
|
if [ ! -d "$baseImages_tarDir" ]; then
|
|
echo "---------$baseImages_tarDir base组件包不存在,退出安装"
|
|
exit 0
|
|
fi
|
|
|
|
find_list=()
|
|
# shellcheck source=/dev/null
|
|
source ./loopDirToFindYamlOrTar.sh $baseImages_tarDir "tar"
|
|
echo "find_list文件个数为: ${#find_list[*]}"
|
|
|
|
#导入 base 镜像
|
|
echo "------3--执行 base 镜像拉取 shell脚本 ---------"
|
|
echo "准备导入 baseImages 组件 镜像"
|
|
for item in ${find_list[*]}; do
|
|
echo "------3--开始 导入 压缩包 ${item} ---------"
|
|
microk8s.ctr image import "$item"
|
|
sleep 2s
|
|
done
|
|
|
|
|
|
|
|
#判断tar 目录是否存在
|
|
baseImage_yamls="./baseImage_yamls"
|
|
if [ ! -d "$baseImage_yamls" ]; then
|
|
echo "---------$baseImage_yamls base组件yaml包不存在,退出安装"
|
|
exit 0
|
|
fi
|
|
|
|
|
|
#启动 base pod
|
|
find_list=()
|
|
# shellcheck source=/dev/null
|
|
source ./loopDirToFindYamlOrTar.sh $baseImage_yamls "yaml"
|
|
echo "f-yaml文件个数为: ${#find_list[*]}"
|
|
|
|
for item in ${find_list[*]}; do
|
|
echo "------3-开始拉取base镜像pod ${item} ---------"
|
|
microk8s.kubectl apply -f ${item}
|
|
sleep 5s
|
|
done
|
|
|
|
|
|
|
|
#-----------------------------------pg 和 es----------------------------
|
|
|
|
echo "准备执行pg创建库脚本"
|
|
#测试用
|
|
pgpodname=$(microk8s.kubectl get pod -n lk | grep pg-deployment- | awk '{print $1}')
|
|
echo " pod名称 $pgpodname"
|
|
|
|
#测试用
|
|
echo "------4--开始执行数据库脚本 ---------"
|
|
#pg数据库 脚本
|
|
#microk8s.kubectl -n lk logs "$(microk8s.kubectl get pod -n lk | grep pg-deployment- | awk '{print $1}')"
|
|
|
|
microk8s.kubectl exec -i "$pgpodname" -n lk -- psql -U postgres <./$baseImage_yamls/启动pg数据库/pgscript/create_db.sql
|
|
sleep 5s
|
|
microk8s.kubectl exec -i "$pgpodname" -n lk -- psql -U postgres -d iota <./$baseImage_yamls/启动pg数据库/pgscript/iota_create.sql
|
|
sleep 5s
|
|
microk8s.kubectl exec -i "$pgpodname" -n lk -- psql -U postgres -d axy <./$baseImage_yamls/启动pg数据库/pgscript/axy_schema.sql
|
|
sleep 5s
|
|
microk8s.kubectl exec -i "$pgpodname" -n lk -- psql -U postgres -d axy <./$baseImage_yamls/启动pg数据库/pgscript/axy_data.sql
|
|
sleep 5s
|
|
|
|
#microk8s.kubectl exec -i pg-deployment-6b5dbdc447-l7qqk -n lk -- psql -U postgres -f script/create_db.sql
|
|
|
|
echo "------4--开始创建es索引 ---------"
|
|
source ./$baseImage_yamls/启动ES和kibana/初始化ES索引/init_es_index.sh
|
|
echo "------4--结束创建es索引 ---------"
|
|
|
|
#kafka pod地址 存入hosts
|
|
sed -i "1i $(microk8s.kubectl -n lk get pod -o wide | grep kafka-deployment- | awk '{print $6,$1}') " /etc/hosts
|
|
echo "------4--查看hosts ---------"
|
|
cat /etc/hosts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#-----------------------------------app----------------------------
|
|
#判断tar 目录是否存在
|
|
appImages_tarDir="./appImage_tars"
|
|
if [ ! -d "$appImages_tarDir" ]; then
|
|
echo "---------$appImages_tarDir app组件包不存在,退出安装"
|
|
exit 0
|
|
fi
|
|
|
|
find_list=()
|
|
# shellcheck source=/dev/null
|
|
source ./loopDirToFindYamlOrTar.sh $appImages_tarDir "tar"
|
|
echo "find_list文件个数为: ${#find_list[*]}"
|
|
|
|
#导入 base 镜像
|
|
echo "------5--执行 app 镜像拉取 shell脚本 ---------"
|
|
echo "准备导入 appImages 组件 镜像"
|
|
for item in ${find_list[*]}; do
|
|
echo "------5--开始 导入 压缩包 ${item} ---------"
|
|
microk8s.ctr image import "$item"
|
|
sleep 2s
|
|
done
|
|
|
|
|
|
#判断tar 目录是否存在
|
|
appImage_yamls="./appImage_yamls"
|
|
if [ ! -d "$appImage_yamls" ]; then
|
|
echo "---------$appImage_yamls app组件yaml包不存在,退出安装"
|
|
exit 0
|
|
fi
|
|
|
|
#启动 app pod
|
|
find_list=()
|
|
# shellcheck source=/dev/null
|
|
source ./loopDirToFindYamlOrTar.sh $appImage_yamls "yaml"
|
|
echo "f-yaml文件个数为: ${#find_list[*]}"
|
|
|
|
for item in ${find_list[*]}; do
|
|
echo "------6--开始拉取base镜像pod ${item} ---------"
|
|
microk8s.kubectl apply -f ${item}
|
|
sleep 5s
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
echo "------7-- 本地化 进程 部署完成 开始使用 ---------"
|
|
|
|
cat dashboard_token.txt
|
|
|
|
#microk8s.kubectl edit svc -n kube-system kubernetes-dashboard
|