【问题标题】:How to get the currentSlot and change the helm upgrade command with the new slot on Azure devops?如何获取 currentSlot 并使用 Azure devops 上的新插槽更改 helm upgrade 命令?
【发布时间】:2020-03-24 09:24:15
【问题描述】:
我正在尝试在 AKS 上为我的 API 实施 CI/CD 管道。我已经成功配置了运行非常顺利的 CI 和 CD 管道,现在我有 2 个名为 Prod 和 Slot 的环境来启用 0 停机时间。
我找到了blue/green deployment 方法。在我的 CD 管道中,我正在尝试设置当前插槽并将其传递给下一步的 helm upgrade 命令
currentSlot=`(helm --client-only get values --all api-poi | grep -Po 'productionSlot: \K.*')`
if [ "$currentSlot" == "blue" ]; then
newSlot="green"
else
newSlot="blue"
fi
但它总是将新闻栏设置为空。可能是什么原因?
$(newSlot).enabled=true
【问题讨论】:
标签:
azure
kubernetes
azure-devops
azure-aks
【解决方案1】:
尝试使用涉及 az aks get-credentials --name 的 Azure CLI 命令而不是 Bash 脚本。
替代的 CLI 命令是
az aks get-credentials --name $(AKSClusterName) --resource-group $(AKSResourceGroup)
currentSlot=$(helm get values --all $(chartName) | grep -oP '(?<=productionSlot: ).*')
if [ "$currentSlot" == "blue" ]; then
newSlot="green"
else
newSlot="blue"
fi
您需要在管道中设置这些 AKSClusterName、AKSResourceGroup、chartName 值或对其进行硬编码