k8s 滚动发布 蓝绿发布 金丝雀发布 灰度发布
k8s

k8s 滚动发布 蓝绿发布 金丝雀发布 灰度发布

axing
2023-08-25 / 0 评论 / 7 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2024年09月29日,已超过115天没有更新,若内容或图片失效,请留言反馈。

先部署

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

评论 (0)

取消