簡介: 藍(lán)綠發(fā)布金絲雀發(fā)布是當(dāng)下互聯(lián)網(wǎng)發(fā)布系統(tǒng)不可繞過的話題。本文演示基于argocd的藍(lán)綠/金絲雀發(fā)布的組件rollout
系列文章同步更新中:
argocd的secret管理之SealedSecret:在git里面加密敏感配置
argocd告警管理之notification服務(wù):讓你第一時(shí)間得到argocd app的狀態(tài)信息
argocd藍(lán)綠/金絲雀發(fā)布之rollout: 快速方便的啟用基于gitops的藍(lán)綠/金絲雀發(fā)布
gitops之a(chǎn)rgocd
一,安裝
rollout是一個(gè)管理k8s副本集的實(shí)現(xiàn)燥透,也是一個(gè)Operator ,部署的時(shí)候需要每個(gè)目標(biāo)集群上都部署,不能像argocd一樣管理多集群。
rollout官網(wǎng)
安裝命令:
kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://raw.githubusercontent.com/argoproj/argo-rollouts/stable/manifests/install.yaml
一如既往的像其他argocd組件一樣方便快捷的安裝方式。
二猜惋,藍(lán)綠發(fā)布啟用
詳情請看清單文件注釋
apiVersion: argoproj.io/v1alpha1
kind: Rollout ##部署完rollout后就有了這個(gè)kind 資源,這個(gè)資源和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: ##藍(lán)綠啟用配置
activeService: rollout-bluegreen-active #生效的服務(wù),需要自己創(chuàng)建建本代碼最下面service資源竭钝。
previewService: rollout-bluegreen-preview #配置預(yù)覽服務(wù)梨撞,同理需要自己創(chuàng)建
autoPromotionEnabled: true ##是否直接切換雹洗,如為true,會在新版本變綠后直接切換到對外服務(wù)卧波。
scaleDownDelayRevisionLimit: 0
previewReplicaCount: 1 #新版本的pod數(shù)量时肿,設(shè)為一個(gè)從而控制資源消耗
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
三,金絲雀發(fā)布啟用
詳情請看清單文件注釋
apiVersion: argoproj.io/v1alpha1
kind: Rollout ##部署完rollout后就有了這個(gè)kind 資源港粱,這個(gè)資源和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: #啟用金絲雀發(fā)布
maxSurge: "25%"
maxUnavailable: 0
steps: ##分步驟階段(每個(gè)階段可以設(shè)置持續(xù)時(shí)間)
- setWeight: 50 #此階段新版本的比重
- pause:
duration: 600 #持續(xù)時(shí)間秒查坪,單位默認(rèn)秒 s/m/h -->秒/分/小時(shí)
- setWeight: 100 ##第二個(gè)階段 階段可以多設(shè)置寸宏,canary發(fā)布會自動完成你設(shè)置的所以步驟
- 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
四,總結(jié)
以上就是argocd 基于gitops理念的藍(lán)綠/灰度發(fā)布實(shí)現(xiàn)偿曙。如果想詳細(xì)了解請移步官方文檔氮凝。