rollout更新策略bluegreen
部署一个示例
[root@master 08-argo-rollouts]# kubectl apply -f 05-argo-rollouts-bluegreen-demo.yaml
rollout.argoproj.io/rollout-helloworld-bluegreen configured
service/spring-boot-helloworld unchanged
service/spring-boot-helloworld-preview unchanged
[root@master 08-argo-rollouts]# cat 05-argo-rollouts-bluegreen-demo.yaml
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-helloworld-bluegreen
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels:
app: rollout-helloworld-bluegreen
template:
metadata:
labels:
app: rollout-helloworld-bluegreen
spec:
containers:
- name: spring-boot-helloworld
image: ikubernetes/spring-boot-helloworld:v0.9.2
ports:
- containerPort: 80
strategy:
blueGreen:
activeService: spring-boot-helloworld
previewService: spring-boot-helloworld-preview
autoPromotionEnabled: false
---
kind: Service
apiVersion: v1
metadata:
name: spring-boot-helloworld
spec:
selector:
app: rollout-helloworld-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: spring-boot-helloworld-preview
spec:
selector:
app: rollout-helloworld-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 80
更新一下镜像版本
[root@master 08-argo-rollouts]# vim 05-argo-rollouts-bluegreen-demo.yaml
spec:
containers:
- name: spring-boot-helloworld
image: ikubernetes/spring-boot-helloworld:v0.9.3
ports:
- containerPort: 80
[root@master 08-argo-rollouts]# kubectl apply -f 05-argo-rollouts-bluegreen-demo.yaml
也可以回滚
版本又变成了0.9.2
在Blue-Green部署上使用analysis
[root@master 08-argo-rollouts]# kubectl apply -f 06-argo-rollouts-bluegreen-with-analysis.yaml
[root@master 08-argo-rollouts]# cat 06-argo-rollouts-bluegreen-with-analysis.yaml
# CopyRight: MageEdu <http://www.magedu.com>
---
apiVersion: argoproj.io/v1alpha1
kind: AnalysisTemplate
metadata:
name: success-rate
spec:
args:
- name: service-name
metrics:
- name: success-rate
successCondition: result[0] >= 0.95
interval: 20s
count: 5
failureLimit: 5
provider:
prometheus:
address: http://prometheus.istio-system.svc.cluster.local:9090
query: |
sum(irate(
istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}",response_code!~"5.*"}[1m]
)) /
sum(irate(
istio_requests_total{reporter="source",destination_service=~"{{args.service-name}}"}[1m]
))
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollout-helloworld-bluegreen-with-analysis
spec:
replicas: 3
revisionHistoryLimit: 5
selector:
matchLabels:
app: rollout-helloworld-bluegreen
template:
metadata:
labels:
app: rollout-helloworld-bluegreen
spec:
containers:
- name: spring-boot-helloworld
image: ikubernetes/spring-boot-helloworld:v0.9.5
ports:
- containerPort: 80
strategy:
blueGreen:
activeService: spring-boot-helloworld
previewService: spring-boot-helloworld-preview
prePromotionAnalysis:
templates:
- templateName: success-rate
args:
- name: service-name
value: spring-boot-helloworld.default.svc.cluster.local
postPromotionAnalysis:
templates:
- templateName: success-rate
args:
- name: service-name
value: spring-boot-helloworld.default.svc.cluster.local
autoPromotionEnabled: true
---
kind: Service
apiVersion: v1
metadata:
name: spring-boot-helloworld
spec:
selector:
app: rollout-helloworld-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: spring-boot-helloworld-preview
spec:
selector:
app: rollout-helloworld-bluegreen
ports:
- protocol: TCP
port: 80
targetPort: 80