K8S - 实现statefulset 有状态service的灰度发布
什么是灰度发布 Canary Release

参考
理解 什么是 滚动更新,蓝绿部署,灰度发布 以及它们的区别
配置partition in updateStrategy/rollingUpdate
这次我为修改了 statefulset 的1个yaml file
statefulsets/stateful-nginx-without-pvc.yaml:
---
apiVersion: v1 # api version
kind: Service # type of this resource e.g. Pod/Deployment ..
metadata:name: nginx-stateful-service # name of the servicelabels:app: nginx-stateful-service
spec:ports: - port: 80 # port of the service, used to access the servicename: web-portclusterIP: None # the service is not exposed outside the clusterselector: # label of the Pod that the Service is selectingapp: nginx-stateful # only service selector could skip the matchLabels:
---apiVersion: apps/v1
kind: StatefulSet # it's for a stateful application, it's a controller
metadata:name: nginx-statefulset # name of the statefulsetlabels:app: nginx-stateful
spec: # detail descriptionserviceName: "nginx-stateful-service" # name of the service that used to manange the dns, # must be the same as the service name defined abovereplicas: 3 # desired replica countselector: # label of the Pod that the StatefulSet is managingmatchLabels:app: nginx-statefultemplate: # Pod templatemetadata:labels:app: nginx-statefulspec:containers:- name: nginx-containeimage: nginx:1.25.4 # image of the containerports: # the ports of the container and they will be exposed- containerPort: 80 # the port used by the container servicename: web-portupdateStrategy:rollingUpdate:partition: 2type: RollingUpdate
关键是最后1个block
updateStrategy:rollingUpdate:partition: 2type: RollingUpdate
rollingUpdate 很容易理解, 关键是partition 的值
这个值表示在image 版本更新后, 只会更新 pod-index 中index >= partition 的POD, 其他POD保持先版本, 这就能同时让两个版本存在一段时间, 实现灰度发布
一个例子
首先我们先apply 上面的yaml
[gateman@manjaro-x13 statefulsets]$ kubectl apply -f stateful-nginx-without-pvc.yaml
service/nginx-stateful-service unchanged
statefulset.apps/nginx-statefulset created
检查pods , 3个pod 起来了分别是0, 1, 2
[gateman@manjaro-x13 statefulsets]$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-statefulset-0 1/1 Running 0 12m 10.244.2.120 k8s-node0 <none> <none>
nginx-statefulset-1 1/1 Running 0 12m 10.244.1.59 k8s-node1 <none> <none>
nginx-statefulset-2 1/1 Running 0 12m 10.244.3.69 k8s-node3 <none> <none>
为了更好的present, 我们把pods数量scale 到5个
[gateman@manjaro-x13 statefulsets]$ kubectl scale statefulset nginx-statefulset --replicas=5
statefulset.apps/nginx-statefulset scaled
[gateman@manjaro-x13 statefulsets]$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-statefulset-0 1/1 Running 0 13m 10.244.2.120 k8s-node0 <none> <none>
nginx-statefulset-1 1/1 Running 0 13m 10.244.1.59 k8s-node1 <none> <none>
nginx-statefulset-2 1/1 Running 0 13m 10.244.3.69 k8s-node3 <none> <none>
nginx-statefulset-3 1/1 Running 0 13s 10.244.2.121 k8s-node0 <none> <none>
nginx-statefulset-4 1/1 Running 0 12s 10.244.3.70 k8s-node3 <none> <none>
这时5个pod 起来了
查看每个pod的image 版本
[gateman@manjaro-x13 statefulsets]$ kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
nginx-statefulset-0 nginx:1.25.4
nginx-statefulset-1 nginx:1.25.4
nginx-statefulset-2 nginx:1.25.4
nginx-statefulset-3 nginx:1.25.4
nginx-statefulset-4 nginx:1.25.4
这时我们更新image 版本从 1.25.4 更新到1.26.1
[gateman@manjaro-x13 statefulsets]$ kubectl set image statefulset/nginx-statefulset nginx-container=nginx:1.26.1
statefulset.apps/nginx-statefulset image updated
再次检查 每个pod 的image version
nginx-statefulset-0 nginx:1.25.4
nginx-statefulset-1 nginx:1.25.4
nginx-statefulset-2 nginx:1.26.1
nginx-statefulset-3 nginx:1.26.1
nginx-statefulset-4 nginx:1.26.1
可以见到只有pod 2 3 和4 更新了, 0, 1 还是旧版本
下一步, 把新版本应到pod 1 和 pod 0
也很简单, 只需要更改partition 的值就行
---
apiVersion: v1 # api version
kind: Service # type of this resource e.g. Pod/Deployment ..
metadata:name: nginx-stateful-service # name of the servicelabels:app: nginx-stateful-service
spec:ports: - port: 80 # port of the service, used to access the servicename: web-portclusterIP: None # the service is not exposed outside the clusterselector: # label of the Pod that the Service is selectingapp: nginx-stateful # only service selector could skip the matchLabels:
---apiVersion: apps/v1
kind: StatefulSet # it's for a stateful application, it's a controller
metadata:name: nginx-statefulset # name of the statefulsetlabels:app: nginx-stateful
spec: # detail descriptionserviceName: "nginx-stateful-service" # name of the service that used to manange the dns, # must be the same as the service name defined abovereplicas: 5 # desired replica countselector: # label of the Pod that the StatefulSet is managingmatchLabels:app: nginx-statefultemplate: # Pod templatemetadata:labels:app: nginx-statefulspec:containers:- name: nginx-containerimage: nginx:1.26.1 # image of the containerports: # the ports of the container and they will be exposed- containerPort: 80 # the port used by the container servicename: web-portupdateStrategy:rollingUpdate:partition: 1type: RollingUpdate
记得修改3个地方, 1是
replicas: 5 改成当前的数量
image: nginx:1.26.1 要改成新的版本
partition: 1 改成1 就是意思把pod 1 也部署新版本
[gateman@manjaro-x13 statefulsets]$ kubectl replace -f stateful-nginx-without-pvc.yaml
service/nginx-stateful-service replaced
statefulset.apps/nginx-statefulset replaced
[gateman@manjaro-x13 statefulsets]$ kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
nginx-statefulset-0 nginx:1.25.4
nginx-statefulset-1 nginx:1.26.1
nginx-statefulset-2 nginx:1.26.1
nginx-statefulset-3 nginx:1.26.1
nginx-statefulset-4 nginx:1.26.1
这时只有pod0 还是旧版本
如何 把pod0 也同步?
方法1是用上面的方法重新更新partition 的值为0
方法2使用 kubectl patch 修改
kubectl patch statefulset nginx-statefulset --type=‘json’ -p=‘[{“op”: “replace”, “path”: “/spec/updateStrategy/rollingUpdate/partition”, “value”: 0}]’
[gateman@manjaro-x13 statefulsets]$ kubectl get pods -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
nginx-statefulset-0 nginx:1.26.1
nginx-statefulset-1 nginx:1.26.1
nginx-statefulset-2 nginx:1.26.1
nginx-statefulset-3 nginx:1.26.1
nginx-statefulset-4 nginx:1.26.1
Deployment 的灰度发布
如果是无状态service 的deployment , 可以用这种方法灰度发布吗?
不行
因为 deployment 的pods 的后续不是1个index 数字, 无序的, 所以无法去比较 pod 的index 和 partition的值
强行写上yaml 就会有如下错误:
[gateman@manjaro-x13 bq-api-service]$ kubectl apply -f bq-api-service-test.yaml
error: error validating "bq-api-service-test.yaml": error validating data: ValidationError(Deployment.spec.strategy.rollingUpdate): unknown field "partition" in io.k8s.api.apps.v1.RollingUpdateDeployment; if you choose to ignore these errors, turn validation off with --validate=false
但是灰度发布只是1个思想, 实现的方法有很多种
deployment的灰度发布在k8s 是可行的, 例如简单粗暴地用多个deployment 去cover 不同的instance. 具体方法不在此讨论
相关文章:
K8S - 实现statefulset 有状态service的灰度发布
什么是灰度发布 Canary Release 参考 理解 什么是 滚动更新,蓝绿部署,灰度发布 以及它们的区别 配置partition in updateStrategy/rollingUpdate 这次我为修改了 statefulset 的1个yaml file statefulsets/stateful-nginx-without-pvc.yaml: --- apiVe…...
Qt 技术博客:深入理解 Qt 中的 delete 和 deleteLater 与信号槽机制
在 Qt 开发中,内存管理和对象生命周期的处理是至关重要的一环。特别是在涉及信号和槽机制时,如何正确删除对象会直接影响应用程序的稳定性。本文将详细讨论在使用 Qt 的信号和槽机制时,delete 和 deleteLater 的工作原理,并给出最…...
自学鸿蒙HarmonyOS的ArkTS语言<一>基本语法
一、一个ArkTs的目录结构 二、一个页面的结构 A、装饰器 Entry 装饰器 : 标记组件为入口组件,一个页面由多个自定义组件组成,但是只能有一个组件被标记 Component : 自定义组件, 仅能装饰struct关键字声明的数据结构 State:组件中的状态变量…...
【OpenGauss源码学习 —— (ALTER TABLE(列存修改列类型))】
ALTER TABLE(列存修改列类型) ATExecAlterColumnType 函数1. 检查和处理列存储表的字符集:2. 处理自动递增列的数据类型检查:3. 处理生成列的类型转换检查:4. 处理生成列的数据类型转换: build_column_defa…...
【大数据 复习】第7章 MapReduce(重中之重)
一、概念 1.MapReduce 设计就是“计算向数据靠拢”,而不是“数据向计算靠拢”,因为移动,数据需要大量的网络传输开销。 2.Hadoop MapReduce是分布式并行编程模型MapReduce的开源实现。 3.特点 (1)非共享式,…...
Zookeeper:节点
文章目录 一、节点类型二、监听器及节点删除三、创建节点四、监听节点变化五、判断节点是否存在 一、节点类型 持久(Persistent):客户端和服务器端断开连接后,创建的节点不删除。 持久化目录节点:客户端与Zookeeper断…...
生产级别的 vue
生产级别的 vue 拆分组件的标识更好的组织你的目录如何解决 props-base 设计的问题transparent component (透明组件)可减缓上述问题provide 和 inject vue-meta 在路由中的使用如何确保用户导航到某个路由自己都重新渲染?测试最佳实践如何制…...
kafka(五)spring-kafka(1)集成方法
一、集成 1、pom依赖 <!--kafka--><dependency><groupId>org.apache.kafka</groupId><artifactId>kafka-clients</artifactId></dependency><dependency><groupId>org.springframework.kafka</groupId><artif…...
Java中的设计模式深度解析
Java中的设计模式深度解析 大家好,我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编,也是冬天不穿秋裤,天冷也要风度的程序猿! 在软件开发领域,设计模式是一种被广泛应用的经验总结和解决方案&#x…...
鸿蒙 HarmonyOS NEXT星河版APP应用开发—上篇
一、鸿蒙开发环境搭建 DevEco Studio安装 下载 访问官网:https://developer.huawei.com/consumer/cn/deveco-studio/选择操作系统版本后并注册登录华为账号既可下载安装包 安装 建议:软件和依赖安装目录不要使用中文字符软件安装包下载完成后࿰…...
[FreeRTOS 基础知识] 互斥访问与回环队列 概念
文章目录 为什么需要互斥访问?使用队列实现互斥访问休眠和唤醒机制环形缓冲区 为什么需要互斥访问? 在裸机中,假设有两个函数(func_A, func_B)都要修改a的值(a),那么将a定义为全局变…...
音视频的Buffer处理
最近在做安卓下UVC的一个案子。正好之前搞过ST方案的开机广告,这个也是我少数最后没搞成功的项目。当时也有点客观原因,当时ST要退出机顶盒市场,所以一切的支持都停了,当时啃他家播放器几十万行的代码,而且几乎没有文档…...
【总结】攻击 AI 模型的方法
数据投毒 污染训练数据 后门攻击 通过设计隐蔽的触发器,使得模型在正常测试时无异常,而面对触发器样本时被操纵输出。后门攻击可以看作是特殊的数据投毒,但是也可以通过修改模型参数来实现 对抗样本 只对输入做微小的改动,使模型…...
Linux配置中文环境
文章目录 前言中文语言包中文输入法中文字体 前言 在Linux系统中修改为中文环境,通常涉及以下几个步骤: 中文语言包 更新源列表: 更新系统的软件源列表和语言环境设置,确保可以安装所需的语言包。 sudo apt update sudo apt ins…...
深入解析 iOS 应用启动过程:main() 函数前的四大步骤
深入解析 iOS 应用启动过程:main() 函数前的四大步骤 背景描述:使用 Objective-C 开发的 iOS 或者 MacOS 应用 在开发 iOS 应用时,我们通常会关注 main() 函数及其之后的执行逻辑,但在 main() 函数之前,系统已经为我们…...
textarea标签改写为富文本框编辑器KindEditor
下载 - KindEditor - 在线HTML编辑器 KindEditor的简单使用-CSDN博客 一、 Maven需要的依赖: 如果依赖无法下载,可以多添加几个私服地址: 在Maven框架中加入镜像私服 <mirrors><!-- mirror| Specifies a repository mirror site to…...
高通安卓12-Input子系统
1.Input输入子系统架构 Input Driver(Input设备驱动层)->Input core(输入子系统核心层)->Event handler(事件处理层)->User space(用户空间) 2.getevent获取Input事件的用法 getevent 指令用于获取android系统中 input 输入事件,比如获取按键上报信息、获…...
HTML 事件
HTML 事件 HTML 事件是发生在 HTML 元素上的交互瞬间,它们可以由用户的行为(如点击、按键、鼠标移动等)或浏览器自身的行为(如页面加载完成、图片加载失败等)触发。在 HTML 和 JavaScript 的交互中,事件扮演着核心角色,允许开发者创建动态和响应式的网页。 常见的 HTM…...
Mysql 官方提供的公共测试数据集 Example Databases
数据集:GitHub - datacharmer/test_db: A sample MySQL database with an integrated test suite, used to test your applications and database servers 下载 test_db: https://github.com/datacharmer/test_db/releases/download/v1.0.7/test_db-1.0.7.tar.gz …...
Docker 下载与安装以及配置
安装yum工具 yum install -y yum-ulits配置yum源 阿里云源 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo安装Docker 17.03后为两个版本: 社区版(Community Edition,缩写为 CE&#x…...
避坑指南:从ADS导入DXF到Altium Designer时,如何解决封装丢失和铺铜失败的常见问题
从ADS到Altium Designer的工程迁移:封装与铺铜问题的深度解决方案 在射频与微波电路设计领域,工程师常常面临一个典型困境:如何在ADS(Advanced Design System)中完成高频仿真后,将设计无缝迁移到Altium Des…...
ARMv9 CPYEN指令:内存拷贝优化技术详解
1. ARM内存拷贝指令CPYEN深度解析 在ARMv9架构中,内存拷贝操作通过专门的硬件指令得到了显著优化。CPYEN指令作为FEAT_MOPS特性的一部分,采用创新的三阶段流水线设计来提升数据传输效率。对于需要频繁处理内存块操作的系统开发者来说,理解这条…...
【免费下载】 华为光猫超级用户名密码获取工具
华为光猫超级用户名密码获取工具 【下载地址】华为光猫超级用户名密码获取工具 华为光猫超级用户名密码获取工具是一款专为华为光猫设计的辅助工具,主要用于获取光猫的VLAN ID。该工具通过将一系列命令编写成批处理文件,实现自动化执行,无需用…...
Warcraft Helper完整指南:让经典魔兽争霸3在现代Windows系统焕发新生
Warcraft Helper完整指南:让经典魔兽争霸3在现代Windows系统焕发新生 【免费下载链接】WarcraftHelper Warcraft III Helper , support 1.20e, 1.24e, 1.26a, 1.27a, 1.27b 项目地址: https://gitcode.com/gh_mirrors/wa/WarcraftHelper 还在为魔兽争霸3在Wi…...
从8251A芯片实战出发:手把手教你用8086汇编完成串口通信初始化编程
从8251A芯片实战出发:手把手教你用8086汇编完成串口通信初始化编程 在嵌入式系统与硬件接口开发领域,掌握串口通信编程是工程师的必修技能。8251A作为经典的通用同步/异步收发器(USART)芯片,至今仍在教学和工业控制领域广泛应用。本文将带您从…...
<数据集>yolo 易拉罐识别<目标检测>
数据集下载链接https://download.csdn.net/download/qq_53332949/92882375数据集格式:VOCYOLO格式 图片数量:3253张 标注数量(xml文件个数):3253 标注数量(txt文件个数):3253 标注类别数:1 标注类别名称ÿ…...
MySQL 跑得稳不稳,Prometheus 得能抓到这个数据才能说清楚
前言 数据库出问题的时候,最怕的不是故障本身,而是故障发生了却没人知道,等用户反馈过来才去翻日志,慢了不止一拍。 MySQL 本身有一些状态变量能反映运行状况——连接数、QPS、缓冲池命中率、慢查询数量——但这些数据要么存着没…...
智能体框架(Harness)深度解析:模型+框架=智能体,一文带你秒懂!
智能体框架(Harness)到底是什么?一文拆透 先把结论摆出来 智能体 模型 框架 如果你不是模型,你就是框架。这个公式听起来简单,但真正理解它需要费点功夫。 所谓框架(Harness),就是…...
雷达接收机频谱稳定与纯度:核心指标、测试方法与设计实战
1. 项目概述:为什么频谱稳定性和纯度是雷达的“生命线”? 在雷达系统里,我们常把发射功率、天线增益、接收机灵敏度这些指标挂在嘴边,因为它们直接决定了雷达能“看”多远。但今天要聊的“接收机频谱稳定性和纯度”,就…...
ESP32-S3 UF2 Bootloader修复指南:从原理到实战救砖
1. 项目概述:为什么ESP32-S3需要UF2 Bootloader?如果你玩过树莓派Pico或者一些Adafruit的开发板,可能会对那个插上USB后出现的U盘盘符有印象——直接把一个.uf2文件拖进去,固件就更新好了,简单得不像在搞嵌入式开发。这…...
