jenkins传统模式发布istio应用

一、发布金丝雀版本

 

Pre Setps

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 旧版本号验证

if [ "$oldVersion" == "" ];then
echo "旧版本号不能为空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vsold.yaml
vsold=$(cat k8s/vsold.yaml)
if [[ $vsold =~ $oldVersion ]];then
echo "旧版本包含"
else
echo "旧版本不包含"
return 0
fi

 

maven

-pl istio-service-user -am clean package

Post Steps

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 使用GitTag作为版本打docker镜像并上传至镜像仓库
docker build -t istio-service-user:${gittag} .
docker tag istio-service-user:${gittag} swr.ap-southeast-1.myhuaweicloud.com/mk-develop/istio-service-user:${gittag}
docker push swr.ap-southeast-1.myhuaweicloud.com/mk-develop/istio-service-user:${gittag}

# 使用GitTag作为版本部署实例
sed -i "s/gittag/${gittag}/g" k8s/istio-service-user-deployment.yaml
mv -f k8s/istio-service-user-deployment.yaml k8s/istio-service-user-deployment-${gittag}.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-deployment-${gittag}.yaml

# 目标规则加入新GitTag版本
/usr/local/bin/kubectl get destinationrules istio-service-user -o yaml > k8s/istio-service-user-destinationrule.yaml
destrule=$(cat k8s/istio-service-user-destinationrule.yaml)
if [[ $destrule =~ $gittag ]];then
echo "目标规则包含"
else
sed -i "\$a\  - name: ${gittag}" k8s/istio-service-user-destinationrule.yaml
sed -i "\$a\    labels:" k8s/istio-service-user-destinationrule.yaml
sed -i "\$a\      version: ${gittag}" k8s/istio-service-user-destinationrule.yaml
fi
/usr/local/bin/kubectl apply -f k8s/istio-service-user-destinationrule.yaml

# 服务路由加入新版本金丝雀
sed -i "s/jsqVersion/${gittag}/g" k8s/istio-service-user-virtualservice-jsq.yaml
sed -i "s/currentVersion/${oldVersion}/g" k8s/istio-service-user-virtualservice-jsq.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-jsq.yaml

 

二、切换为生产版本(上线)

Pre Steps

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 生产版本号验证
if [ "$proVersion" == "" ];then
echo "生产版本号不能为空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vspro.yaml
vspro=$(cat k8s/vspro.yaml)
if [[ $vspro =~ $proVersion ]];then
echo "生产版本存在"
else
echo "生产版本不存在"
return 0
fi

#替换生产版本号
sed -i "s/proVersion/${proVersion}/g" k8s/istio-service-user-virtualservice-pro.yaml
mv -f k8s/istio-service-user-virtualservice-pro.yaml k8s/istio-service-user-virtualservice-${proVersion}.yaml
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-${proVersion}.yaml
rm -rf k8s/istio-service-user-virtualservice-${oldVersion}.yaml

if [ "$oldVersion" == "" ];then
echo "未下线旧版本"
else
/usr/local/bin/kubectl delete -f k8s/istio-service-user-deployment-${oldVersion}.yaml
rm -rf k8s/istio-service-user-deployment-${oldVersion}.yaml
fi

 

三、下线已上线金丝雀(回滚)

 

Pre Steps

cd /var/lib/jenkins/workspace/istio-service-user-canary/istio-service-user

# 金丝雀版本号验证
if [ "$jsqVersion" == "" ];then
echo "金丝雀版本号不能为空"
return 0
fi
/usr/local/bin/kubectl get virtualservice istio-service-user -o yaml > k8s/vspro.yaml
vspro=$(cat k8s/vspro.yaml)
if [[ $vspro =~ $proVersion ]];then
echo "金丝雀版本号存在"
else
echo "金丝雀版本号不存在"
return 0
fi

#替换生产版本号
/usr/local/bin/kubectl apply -f k8s/istio-service-user-virtualservice-${rollbackVersion}.yaml

#删除金丝雀版本发布
/usr/local/bin/kubectl delete -f k8s/istio-service-user-deployment-${jsqVersion}.yaml 
rm -rf k8s/istio-service-user-deployment-${jsqVersion}.yaml 

 

posted @ 2019-08-13 21:50  Assion Yang  阅读(645)  评论(0编辑  收藏  举报