First, the on-line version of the canary
for setps
CD / var / lib / Jenkins / Workspace / istio-Service-User-/ istio-Service- User # old version number validation IF [ " $ oldVersion " == "" ]; the then echo " of the old version can not be null " 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]]; the then echo " old version contains " the else echo " the old version does not include the " 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 used as a play version docker mirror image and upload it to the warehouse docker Build -t-Service- istio User:. $ {} gittag docker istio Tag -service-User: $ {} swr.ap gittag-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 used as the version example deployment Sed -i " S / gittag /} $ {gittag / G " K8S / istio-user--Service- deployment.yaml Music Videos - 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-user--Service- destinationrule.yaml # routing service to a new version of canary Sed -i " S / jsqVersion /} $ {gittag / G " K8S / istio- User-virtualservice---Service 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
Second, the production version of the switching (on-line)
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
三、下线已上线金丝雀(回滚)
要