先部署
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: production
name: production
spec:
replicas: 1 # 为了测试方便,就设置1个副本吧
selector:
matchLabels:
app: production
strategy: {}
template:
metadata:
labels:
app: production
spec:
containers:
- image: nginx:1.18
name: nginx
---
apiVersion: v1
kind: Service
metadata:
labels:
app: production
name: production
spec:
ports:
- port: 9999
protocol: TCP
targetPort: 80
selector:
app: production
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: production
spec:
ingressClassName: nginx
rules:
- host: egon.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: production
port:
number: 9999
滚动更新
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: canary
annotations:
nginx.ingress.kubernetes.io/canary: 'true' # 要开启金丝雀发布机制,首先需要启用 Canary
nginx.ingress.kubernetes.io/canary-weight: '30' # 分配30%流量到当前Canary版本
spec:
ingressClassName: nginx
rules:
- host: egon.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: canary
port:
number: 9999
金丝雀
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: canary
annotations:
nginx.ingress.kubernetes.io/canary: 'true' # 要开启金丝雀发布机制,首先需要启用 Canary
nginx.ingress.kubernetes.io/canary-by-header: canary
nginx.ingress.kubernetes.io/canary-by-header-value: user-value
nginx.ingress.kubernetes.io/canary-weight: '30' # 分配30%流量到当前Canary版本
spec:
ingressClassName: nginx
rules:
- host: egon.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: canary
port:
number: 9999
灰度发布
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: canary
annotations:
nginx.ingress.kubernetes.io/canary: 'true' # 要开启金丝雀发布机制,首先需要启用 Canary
nginx.ingress.kubernetes.io/canary-by-cookie: 'users_from_Shanghai'
nginx.ingress.kubernetes.io/canary-weight: '30' # 分配30%流量到当前Canary版本
spec:
ingressClassName: nginx
rules:
- host: egon.ingress.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: canary
port:
number: 9999
评论 (0)