1 前提
1.1 使用deployment 控制器管理pod
1.2 项目每次发布前,需要使用git打tag
2 使用jenkins将项目部署到k8s中
以项目admin为例:
admin是一个java项目
创建一个admin的item
c=`mvn dependency:list | grep -i snapshot | grep -v "0.0.1-SNAPSHOT"|| true` if [ ${c}=="" ];then echo -e "\033[32m[ 可以正常构建 ]\033[0m" else echo -e "\033[31m[ 服务包含SNAPSHOT,打包失败 ! ]\033[0m" exit 2 fi
#/bin/bash regular="^v[0-9]+.[0-9]+.[0-9]*" echo "发布的分支是:$branch" # git提交的hash hash=`git log --pretty=format:"%h" | head -n 1` if [[ $branch =~ $regular ]];then con_tag=$branch-$hash else git_tag=`git tag -l --points-at origin/stable | grep -oE '^v[0-9]+(\.[0-9]+)+$'` con_tag=$git_tag-$hash fi echo -e "\033[32m 容器的tag是: ${con_tag}\033[0m" sudo docker build -t registry-vpc.cn-beijing.aliyuncs.com/cn_genebox/laso-admin:$con_tag . sudo docker push registry-vpc.cn-beijing.aliyuncs.com/cn_genebox/laso-admin:$con_tag ansible 172.17.209.36 -m script -a "/home/jenkins/shell/prd_deploy_pod.sh laso-admin $con_tag laso-admin " -u root # 发版发钉钉通知 python3 /home/jenkins/python/dingding.py ${BUILD_USER} laso-admin ${branch} ${BUILD_NUMBER}
# 判断依赖是不是最新版本的 python3 /home/jenkins/python/java_rely.py ${BUILD_USER} prd-laso-admin