jenkins传统模式发布istio应用

一、上线金丝雀版本

jenkins传统模式发布istio应用

 

Pre Setps

cd /var/lib/jenkins/workspace/istio-service-user/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/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
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
/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

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

jenkins传统模式发布istio应用

Pre Steps

cd /var/lib/jenkins/workspace/istio-service-user/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

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

 

上一篇:基于 K8S 集群安装部署 istio-1.2.4


下一篇:等不及官宣——Istio 1.0.3 Release Notes