首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >K8s实现最简单灰度发布

K8s实现最简单灰度发布

作者头像
院长技术
发布2020-06-13 09:42:32
9.9K0
发布2020-06-13 09:42:32
举报

灰度发布又名金丝雀部署,是让部分用户访问到新版本应用,在 Kubernetes 中,可以使用两个具有相同 Pod 标签的 Deployment 来实现金丝雀部署。新版本的副本和旧版本的一起发布。在一段时间后如果没有检测到错误,则可以扩展新版本的副本数量并删除旧版本的应用。

v1版本

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: tomcat-test
  name: tomcat-test-v1
  namespace: test
spec:
  minReadySeconds: 100
  replicas: 4
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: tomcat-test
      version: v1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        initializer.kubernetes.io/lxcfs: 'true'
      labels:
        app: tomcat-test
        version: v1
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - tomcat-test
            topologyKey: kubernetes.io/hostname
      containers:
      - env:
        - name: HOST_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: POD_NAME
          value: tomcat-test
        - name: version
          value: v1
        image: vnet01-harbor.sy.cn/test/tomcat-test:r-20200214_175535
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /abc/check_health.jsp
            port: 6080
          initialDelaySeconds: 80
          timeoutSeconds: 20
        name: tomcat-test
        readinessProbe:
          httpGet:
            path: /abc/check_health.jsp
            port: 6080
          initialDelaySeconds: 80
          timeoutSeconds: 20
        resources:
          limits:
            cpu: '2'
            memory: 4096M
          requests:
            cpu: '1'
            memory: 2048M
        volumeMounts:
        - mountPath: /data/logs
          name: app-log
          readOnly: false
      nodeSelector:
        apptype: memnode
      terminationGracePeriodSeconds: 60
      volumes:
      - hostPath:
          path: /var/lib/docker/logs/tomcat-test
        name: app-log

v2版本

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: tomcat-test
  name: tomcat-test-v2
  namespace: test
spec:
  minReadySeconds: 100
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: tomcat-test
      version: v2
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        initializer.kubernetes.io/lxcfs: 'true'
      labels:
        app: tomcat-test
        version: v2
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - tomcat-test
            topologyKey: kubernetes.io/hostname
      containers:
      - env:
        - name: HOST_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: POD_NAME
          value: tomcat-test
        - name: version
          value: v2
        image: vnet01-harbor.sy.cn/test/tomcat-test:r-20200319_101302
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /abc/check_health.jsp
            port: 6080
          initialDelaySeconds: 80
          timeoutSeconds: 20
        name: tomcat-test
        readinessProbe:
          httpGet:
            path: /abc/check_health.jsp
            port: 6080
          initialDelaySeconds: 80
          timeoutSeconds: 20
        resources:
          limits:
            cpu: '2'
            memory: 4096M
          requests:
            cpu: '1'
            memory: 2048M
        volumeMounts:
        - mountPath: /data/logs
          name: app-log
          readOnly: false
      nodeSelector:
        apptype: memnode
      terminationGracePeriodSeconds: 60
      volumes:
      - hostPath:
          path: /var/lib/docker/logs/tomcat-test
        name: app-log

流量比就是4:1

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档