当前位置: 首页 > news >正文

k8s使用ingress实现应用的灰度发布升级

v1是1.14.0版本nginx ,实操时候升级到v2是1.20.0版本nginx,来测试灰度发布实现过程

一、方案:使用ingress实现应用的灰度发布

1、服务端:正常版本v1,灰度升级版本v2

2、客户端:带有请求头version=v2标识的请求访问版本v2,其他的请求访问版本v1

3、待版本v2稳定后,所有请求切换至版本v2,停止版本v1(删除原deployment,service,ingress)

二、操作步骤

1、创建版本v1的deployment、service、ingress

nginx服务版本v1的deployment和service

nginx-v1.yml

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-v1
spec:selector:matchLabels:app: nginx-v1replicas: 1template:metadata:labels:app: nginx-v1spec:containers:- name: nginximage: nginx:1.14.0ports:- containerPort: 80volumeMounts:- mountPath: /usr/share/nginx/htmlname: filevolumes:- name: filehostPath:path: /data/nginx-v1
---
apiVersion: v1
kind: Service
metadata:name: nginx-v1-svc  labels:app: nginx-v1   
spec:type: ClusterIP  selector:app: nginx-v1ports:- port: 80targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-v1
spec:ingressClassName: nginxrules:- host: test.nginx.comhttp:paths:- path: /pathType: Prefixbackend:service:name: nginx-v1-svc port:number: 80

验证:apifox 调用test.nginx.com,当前所有请求都正常访问版本v1,即1.14版本nginx

2、创建版本v2的deployment、service、ingress

nginx服务版本v2的deployment、service

nginx-v2.yml

apiVersion: apps/v1
kind: Deployment
metadata:name: nginx-v2
spec:selector:matchLabels:app: nginx-v2replicas: 1template:metadata:labels:app: nginx-v2spec:containers:- name: nginximage: nginx:1.20.0ports:- containerPort: 80volumeMounts:- mountPath: /usr/share/nginx/htmlname: filevolumes:- name: filehostPath:path: /data/nginx-v2
---
apiVersion: v1
kind: Service
metadata:name: nginx-v2-svc  labels:app: nginx-v2   
spec:type: ClusterIP  selector:app: nginx-v2ports:- port: 80targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:name: nginx-v2annotations:nginx.ingress.kubernetes.io/canary: "true"nginx.ingress.kubernetes.io/canary-by-header: "version"  #请求头key=versionnginx.ingress.kubernetes.io/canary-by-header-value: "v2"  #请求头value=v2
spec:ingressClassName: nginxrules:- host: test.nginx.comhttp:paths:- path: /pathType: Prefixbackend:service:name: nginx-v2-svc port:number: 80

nginx服务版本v2的ingress,匹配请求头version=2访问

验证:postman调用test.nginx.com,加了请求头version=v2的请求访问版本v2,即1.20版nginx,其他请求访问版本v1

三、方案:使用k8s 配置 RollingUpdate 滚动更新实现应用的灰度发布

spec:
  replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量
  progressDeadlineSeconds: 600 #在Deployment 在进度卡住6分钟后报告
  minReadySeconds: 120 #Pod被认为是可用状态的最小秒数,然后加入nacos 可用。默认是0
  strategy:
    rollingUpdate:
      maxSurge: 1 #升级过程中激增Pod的最大数量
      maxUnavailable: 0 #升级过程中不可用Pod的最大数量
    type: RollingUpdate

apiVersion: v1
kind: Service
metadata:name: $IMG_NAMEnamespace: rz-dtlabels:app: $IMG_NAME
spec:type: NodePortports:- port: 8091nodePort: 31082 #service对外开放端口selector:app: $IMG_NAME
---
apiVersion: apps/v1
kind: Deployment #对象类型
metadata:name: $IMG_NAME #名称namespace: rz-dtlabels:app: $IMG_NAME #标注
spec:replicas: 1 #运行容器的副本数,修改这里可以快速修改分布式节点数量progressDeadlineSeconds: 600 #在Deployment 在进度卡住6分钟后报告minReadySeconds: 120 #Pod被认为是可用状态的最小秒数,然后加入nacos 可用。默认是0strategy:rollingUpdate:maxSurge: 1 #升级过程中激增Pod的最大数量maxUnavailable: 0 #升级过程中不可用Pod的最大数量type: RollingUpdateselector:matchLabels:app: $IMG_NAMEtemplate:metadata:labels:app: $IMG_NAMEspec:containers: #docker容器的配置- name: $IMG_NAMEenv:- name: aliyun_logs_catalinavalue: stdoutimage: rz-dt-image-server-registry-vpc.cn-shanghai.cr.aliyuncs.com/rz-dt/$IMG_NAME:$IMG_TAG # pull镜像的地址 ip:prot/dir/images:tagimagePullPolicy: Always #pull镜像时机,#command: ["java","-Dserver.port=8055","-jar","/usr/local/cenobitor/k8s-springboot-demo.jar"]ports:- containerPort: 8091 #容器对外开放端口,需与springboot配置文件一致volumeMounts:- name: time-configmountPath: /etc/localtimereadOnly: true- name: volume-logsmountPath: /logssubPath: logsresources:limits:cpu: 500mmemory: 1Girequests:cpu: 10mmemory: 50Mi#从私有仓库拉取镜像凭证imagePullSecrets:- name: rz-dt-miyue-vpcvolumes:- name: time-confighostPath:path: /usr/share/zoneinfo/Asia/Shanghai- name: volume-logspersistentVolumeClaim:claimName: rz-dt-nas-volume-claim

http://www.lryc.cn/news/286349.html

相关文章:

  • 最新热门商用GPT4.0带MJ绘画去授权版本自定义三方接口(开心版)
  • Halcon基于形状的模板匹配inspect_shape_model
  • html中根元素以及根元素字体的含义
  • 51单片机1-6
  • vue2(Vuex)、vue3(Pinia)、react(Redux)状态管理
  • 用户画像项目背景
  • Go使用记忆化搜索的套路【以20240121力扣每日一题为例】
  • 【LeetCode】每日一题 2024_1_21 分割数组的最大值(二分)
  • bevy the book 20140118翻译(全)
  • MySQL数据库面试知识点
  • 超优秀的三维模型轻量化、格式转换、可视化部署平台!
  • 云原生全栈监控解决方案(全面详解)
  • 代码随想录二刷 | 回溯 |复原IP地址
  • windows资源管理器占用过高CPU的问题
  • redis的常见数据类型和应用场景(非八股)------大总结(学了要会用-------教你如何使用)
  • UE 可靠UDP实现原理
  • 智慧博物馆信息化系统建设(1)
  • 【数据结构和算法】--- 二叉树(3)--二叉树链式结构的实现(1)
  • Cesium for Unity包无法加载
  • Leetcode—40.组合总和II【中等】
  • vscode连不上虚拟机,一直密码错误
  • 力扣每日一题 --- 972. 相等的有理数
  • EXECL 单元格字符串链接 CONCAT :应用:将一行数据转为json
  • 基于Python实现人脸识别相似度对比
  • CSS 蜡烛效果
  • 渗透测试之Kali如何利用CVE-2019-0708漏洞渗透Win7
  • Docker(二)安装指南:主要介绍在 Linux 、Windows 10 和 macOS 上的安装
  • LeetCode 410. 分割数组的最大值
  • linux shell脚本 基础认识
  • 一文(10图)了解Cornerstone3D核心概念(万字总结附导图)