📍 导航:返回目录 | 上一节:Kubernetes
stages:
- build
- test
- deploy
build:
stage: build
script:
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
test:
stage: test
script:
- go test ./...
deploy:
stage: deploy
script:
- kubectl set image deployment/my-app app=$CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
only:
- master# 灰度版本(10%流量)
apiVersion: v1
kind: Service
metadata:
name: my-app-canary
spec:
selector:
app: my-app
version: v2
ports:
- port: 80
# 配置流量比例
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-app
spec:
hosts:
- my-app
http:
- match:
- headers:
canary:
exact: "true"
route:
- destination:
host: my-app
subset: v2
- route:
- destination:
host: my-app
subset: v1
weight: 90
- destination:
host: my-app
subset: v2
weight: 10关键要点:
- ✅ GitLab CI自动化流水线
- ✅ 蓝绿部署零停机
- ✅ 灰度发布降低风险
- ✅ IaC基础设施即代码
⏮️ 上一节:Kubernetes |
⏏️ 返回目录