
过去,可怜的金丝雀会作为试验品,用来测试煤矿中甲烷的含量。用绳子将装有金丝雀的笼子放入矿井一段时间,再拉上来,如果金丝雀还活着,矿井就可以安全开采;如果金丝雀死亡,则不能开采。现在,这种方法早已弃用,因为这对动物太不人道了。

金丝雀总是在矿工身边徘徊,如果它停止鸣叫,则表示矿工必须离开矿井。
金丝雀部署是指两个版本的应用共存,新版本在开始时规模较小,处理的负载流量也较少。随着对新部署的分析,所有请求逐渐切换到新版本,而旧版本应用被移除。
人们普遍认为,管理这些部署的流量需要使用一个?Service Mesh,然而,要管理入站流量,你只需在 nginx ingress controller 上设置 annotations 即可:
nginx.ingress.kubernetes.io/canary: ?"true"
nginx.ingress.kubernetes.io/canary-weight: ?<num>
这种方法的缺点是必须手动管理。为了实现自动化,我们可以使用 Argo Rollouts (https://argoproj.github.io/argo-rollouts/)。
运行Argo Rollouts
添加 helm-repo: https://argoproj.github.io/argo-helm

argo-rollouts chart:

Helm-values:
installCRDs: true
修改 Deployment 并运行 Rollouts CRD
ScaleDown deployment,设置 Replicas 0:

运行 service
apiVersion: v1
kind: Service
metadata:
annotations:
argo-rollouts.argoproj.io/managed-by-rollouts: rollout-pregap
name: rollouts-pregap-canary
namespace: pregap
spec:
clusterIP: 10.43.139.197
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: test2-pregap
sessionAffinity: None
type: ClusterIP
apiVersion: v1
kind: Service
metadata:
annotations:
argo-rollouts.argoproj.io/managed-by-rollouts: rollout-pregap
spec:
clusterIP: 10.43.61.221
ports:
- name: http
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: test2-pregap
sessionAffinity: None
type: ClusterIP
运行 Rollouts CRD

由于我们不想更改Deployment,因此在Rollout manifest中引用它:workloadRef.kind: Deployment, workloadRef.name

运行 manifest 将创建额外 ingress:

Argo Rollouts 仪表板


CD-pipeline 中的其他步骤
在.drone.yml 中添加提升步骤:
- name: promote-release-dr
image: plugins/docker
settings:
repo: 172.16.77.115:5000/pregap
registry: 172.16.77.115:5000
insecure: true
dockerfile: Dockerfile.multistage
tags:
- latest
- ${DRONE_TAG##v}
when:
event:
- promote
target:
- production
- name: promote-release-prod
image: plugins/webhook
settings:
username: admin
password: admin
urls: http://172.16.77.118:9300/v1/webhooks/native
debug: true
content_type: application/json
template: |
{ "name": "172.16.77.115:5000/pregap",
"tag": "${DRONE_TAG##v}" }
when:
event:
- promote
target:
- production


添加 Keel 审批:

结? 论
金丝雀部署或绿/蓝部署一点都不难 - 它将提高生产环境的可靠性,并在出现任何设计错误时减少受影响的区域。将来,我会在服务器上添加 RAM,而且有可能启用Prometheus 监控和 Istio,并尝试执行分析和实验阶段,以实现 Argo Rollouts。
|