argocd蓝绿/金丝雀发布之rollout

封面

简介: 蓝绿发布金丝雀发布是当下互联网发布系统不可绕过的话题。本文演示基于argocd的蓝绿/金丝雀发布的组件rollout

系列文章同步更新中:

argocd的secret管理之SealedSecret:在git里面加密敏感配置
argocd告警管理之notification服务:让你第一时间得到argocd app的状态信息
argocd蓝绿/金丝雀发布之rollout: 快速方便的启用基于gitops的蓝绿/金丝雀发布
gitops之argocd

一,安装

rollout是一个管理k8s副本集的实现,也是一个Operator ,部署的时候需要每个目标集群上都部署,不能像argocd一样管理多集群。
rollout官网
安装命令:

kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://raw.githubusercontent.com/argoproj/argo-rollouts/stable/manifests/install.yaml

一如既往的像其他argocd组件一样方便快捷的安装方式。


rollout deployment
二,蓝绿发布启用

详情请看清单文件注释

apiVersion: argoproj.io/v1alpha1
kind: Rollout  ##部署完rollout后就有了这个kind 资源,这个资源和deployment类似也是管理你的副本集的,所以不能像deployment那样在k8s界面看见,只能通过kubectl命令行
metadata:
  name: rollout-bluegreen
  namespace: rollout-test
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - resources: #{}
          requests:
            cpu: "1"
            memory: "2Gi"
          limits:
            cpu: "2"
            memory: "2Gi"
        terminationMessagePolicy: File
        imagePullPolicy: Always
        name: rollout-bluegreen
        image: argoproj/rollouts-demo:green #nginx:1.17.1
      schedulerName: default-scheduler
      securityContext: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
    metadata:
      labels:
        app: rollout-bluegreen
  selector:
    matchLabels:
      app: rollout-bluegreen
  replicas: 2
  strategy:
    blueGreen:  ##蓝绿启用配置
      activeService: rollout-bluegreen-active   #生效的服务,需要自己创建建本代码最下面service资源。
      previewService: rollout-bluegreen-preview  #配置预览服务,同理需要自己创建
      autoPromotionEnabled: true  ##是否直接切换,如为true,会在新版本变绿后直接切换到对外服务。
      scaleDownDelayRevisionLimit: 0
      previewReplicaCount: 1  #新版本的pod数量,设为一个从而控制资源消耗
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
    type: RollingUpdate
  revisionHistoryLimit: 2
  progressDeadlineSeconds: 600

---
apiVersion: v1
kind: Service
metadata:
  name: rollout-bluegreen-active
  namespace: rollout-test
spec:
  sessionAffinity: None
  selector:
    app: rollout-bluegreen
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: LoadBalancer

三,金丝雀发布启用

详情请看清单文件注释

apiVersion: argoproj.io/v1alpha1
kind: Rollout  ##部署完rollout后就有了这个kind 资源,这个资源和deployment类似也是管理你的副本集的,所以不能像deployment那样在k8s界面看见,只能通过kubectl命令行
metadata:
  name: rollout-bluegreen
  namespace: rollout-test
spec:
  template:
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - resources: #{}
          requests:
            cpu: "1"
            memory: "2Gi"
          limits:
            cpu: "2"
            memory: "2Gi"
        terminationMessagePolicy: File
        imagePullPolicy: Always
        name: rollout-bluegreen
        image: argoproj/rollouts-demo:green #nginx:1.17.1
      schedulerName: default-scheduler
      securityContext: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
    metadata:
      labels:
        app: rollout-bluegreen
  selector:
    matchLabels:
      app: rollout-bluegreen
  replicas: 2
  strategy:
    canary:  #启用金丝雀发布
      maxSurge: "25%"
      maxUnavailable: 0
      steps:     ##分步骤阶段(每个阶段可以设置持续时间)
      - setWeight: 50   #此阶段新版本的比重
      - pause:
          duration: 600  #持续时间秒,单位默认秒  s/m/h  -->秒/分/小时
      - setWeight: 100  ##第二个阶段  阶段可以多设置,canary发布会自动完成你设置的所以步骤
      - pause: {}   
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
    type: RollingUpdate
  revisionHistoryLimit: 2
  progressDeadlineSeconds: 600

---
apiVersion: v1
kind: Service
metadata:
  name: rollout-bluegreen-active
  namespace: rollout-test
spec:
  sessionAffinity: None
  selector:
    app: rollout-bluegreen
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: LoadBalancer

四,总结

以上就是argocd 基于gitops理念的蓝绿/灰度发布实现。如果想详细了解请移步官方文档。

你可能感兴趣的:(argocd蓝绿/金丝雀发布之rollout)