內容目錄
Argo Rollouts 是一個 Kubernetes 的擴展資源,它提供了一種名為"藍綠部署"(Blue-Green Deployment)的部署策略。藍綠部署是一種漸進式的部署方式,可以幫助您在不中斷服務的情況下進行應用程序的更新。
以下是 Argo Rollouts 藍綠部署的主要特點和工作原理:
- 兩個版本並行部署:
- 藍色環境(blue)代表當前的穩定版本。
- 綠色環境(green)代表新版本。
- 兩個版本會同時部署在 Kubernetes 集群中。
- 流量切換:
- 流量最初會全部路由到藍色環境。
- 當新版本準備就緒後,可以逐步將流量切換到綠色環境。
- 流量切換可以通過修改 Service 或 Ingress 的設定來實現。
- 回滾機制:
- 如果新版本出現問題,可以快速將流量切換回藍色環境,實現回滾。
- 這可以最大限度地減少服務中斷。
- 金絲雀發佈:
- Argo Rollouts 支持金絲雀發佈(Canary)策略,可以逐步將流量遷移到新版本。
- 這樣可以在生產環境中測試新版本,並在出現問題時快速回滾。
- 自動化管理:
- Argo Rollouts 提供了聲明式的 API,開發人員可以定義部署策略。
- 部署過程可以由 Argo Rollouts 自動化管理,減少人工操作。
金絲雀部署
Argo Rollouts helm Install
kubectl create namespace argocd helm repo add argo https://argoproj.github.io/argo-helm cd argo-rollouts && helm install argo-rollouts ./ -f ./values.yaml -n argocd
Argocd Rollouts指令安裝
Mac
arch -arm64 brew install argoproj/tap/kubectl-argo-rollouts
Linux
curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-darwin-amd64 chmod +x ./kubectl-argo-rollouts-darwin-amd64 sudo mv ./kubectl-argo-rollouts-darwin-amd64 /usr/local/bin/kubectl-argo-rollouts kubectl argo rollouts version
Argo CLI
curl -sLO https://github.com/argoproj/argo-workflows/releases/download/v3.5.10/argo-darwin-amd64.gz gunzip argo-darwin-amd64.gz chmod +x argo-darwin-amd64 mv ./argo-darwin-amd64 /usr/local/bin/argo argo version
金丝雀部署 (DEMO)
basic-rollout.yaml
# basic-rollout.yaml apiVersion: argoproj.io/v1alpha1 kind: Rollout metadata: name: rollouts-demo spec: replicas: 5 # 定义5个副本 strategy: # 定义升级策略 canary: # 金丝雀发布 steps: # 发布的节奏 - setWeight: 20 - pause: {} # 会一直暂停 - setWeight: 40 - pause: {duration: 10} # 暂停10s - setWeight: 60 - pause: {duration: 10} - setWeight: 80 - pause: {duration: 10} revisionHistoryLimit: 2 # 下面部分其实是和 Deployment 兼容的 selector: matchLabels: app: rollouts-demo template: metadata: labels: app: rollouts-demo spec: containers: - name: rollouts-demo image: argoproj/rollouts-demo:red ports: - name: http containerPort: 8080 protocol: TCP resources: requests: memory: 32Mi cpu: 5m
basic-service.yaml
# basic-service.yaml apiVersion: v1 kind: Service metadata: name: rollouts-demo spec: ports: - port: 80 targetPort: http protocol: TCP name: http selector: app: rollouts-demo
Apply yaml
kubectl apply -f basic-rollout.yaml kubectl apply -f basic-service.yaml
查看服務狀態
kubectl argo rollouts get rollout rollouts-demo --watch Name: rollouts-demo Namespace: default Status: ✔ Healthy Strategy: Canary Step: 8/8 SetWeight: 100 ActualWeight: 100 Images: argoproj/rollouts-demo:red (stable) Replicas: Desired: 5 Current: 5 Updated: 5 Ready: 5 Available: 5 NAME KIND STATUS AGE INFO ⟳ rollouts-demo Rollout ✔ Healthy 15m └──# revision:1 └──⧉ rollouts-demo-5747959bdb ReplicaSet ✔ Healthy 15m stable ├──□ rollouts-demo-5747959bdb-cclwh Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-j2m5x Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-nldw9 Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-pdgdh Pod ✔ Running 15m ready:1/1 └──□ rollouts-demo-5747959bdb-rdssn Pod ✔ Running 15m ready:1/1 Name: rollouts-demo Namespace: default Status: ✔ Healthy Strategy: Canary Step: 8/8 SetWeight: 100 ActualWeight: 100 Images: argoproj/rollouts-demo:red (stable) Replicas: Desired: 5 Current: 5 Updated: 5 Ready: 5 Available: 5 NAME KIND STATUS AGE INFO ⟳ rollouts-demo Rollout ✔ Healthy 15m └──# revision:1 └──⧉ rollouts-demo-5747959bdb ReplicaSet ✔ Healthy 15m stable ├──□ rollouts-demo-5747959bdb-cclwh Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-j2m5x Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-nldw9 Pod ✔ Running 15m ready:1/1 ├──□ rollouts-demo-5747959bdb-pdgdh Pod ✔ Running 15m ready:1/1 └──□ rollouts-demo-5747959bdb-rdssn Pod ✔ Running 15m ready:1/1
更新 Rollout
update images
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:blue
Promote Rollout 從pause進入下一個階段
kubectl argo rollouts promote rollouts-demo
暫停部署
kubectl argo rollouts pause rollouts-demo
恢復暫停部署
kubectl argo rollouts resume rollouts-demo
中止當前部署
kubectl argo rollouts abort rollouts-demo
執行結果
中斷Rollout
kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:yellow
kubectl argo rollouts abort rollouts-demo
藍綠部署
部署 (DEMO)
kubectl apply -f bluegreen-rollout.yaml
版更
kubectl argo rollouts set image rollout-bluegreen rollouts-demo=argoproj/rollouts-demo:red
promote至新版本 UI介面手動點選promote或是CLI
kubectl argo rollouts promote rollout-bluegreen
執行結果