这里是一些链接https://github.com/openkruise/kruise-tools/releases/tag/v1.1.5
https://openkruise.io/zh/rollouts/user-manuals/basic-usage/
https://github.com/openkruise/kruise-tools#install-manually
https://help.aliyun.com/zh/ack/ack-managed-and-ack-dedicated/user-guide/use-kruise-rollout-to-perform-canary-releases-and-a-b-testing?spm=a2c4g.11186623.0.i3#section-qs9-arl-hvo

1、我这边是在阿里云的ack集群验证的,需要在组件管理安装ack-kruise组件。

2、需要安装kubectl-kruise客户端,安装方法直接下载kubectl-kruise-linux-amd64-v1.1.5.tar.gz包解压即可。

k8s之Kruise Rollouts灰度发布_Deployment

3、编写对应yaml文件。

cat svip-dubbo-manager.yaml apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:name: svip-dubbo-manager-deploymentnamespace: server-sviplabels:app: svip-dubbo-manager
spec:replicas: 2selector:matchLabels:app: svip-dubbo-managertemplate:metadata:labels:app: svip-dubbo-managerspec:topologySpreadConstraints: # 拓扑分布约束- maxSkew: 1 # 允许的最大偏差为 1topologyKey: kubernetes.io/hostname # 拓扑键为节点的主机名whenUnsatisfiable: DoNotSchedule # 如果无法满足约束条件,则不调度 PodlabelSelector: # 选择带有以下标签的 PodmatchLabels:app: svip-dubbo-managerimagePullSecrets:- name: harbor-regcredcontainers:- name: svip-dubbo-managerimage: xxx/svip/production/svip-dubbo-manager:v24.11.06.1840_20240828_ackimagePullPolicy: Always # 添加这一行,确保总是重新拉取镜像lifecycle:postStart:exec:command:- /bin/sh- '-c'- /usr/sbin/crondenv:- name: aliyun_logs_ack-prod-java-svip-manager-dubbovalue: /data2/logs/svip-dubbo-manager/newcomlog.logports:- containerPort: 20884livenessProbe:tcpSocket:port: 33302initialDelaySeconds: 150periodSeconds: 10readinessProbe:tcpSocket:port: 33302initialDelaySeconds: 90periodSeconds: 30resources:limits:cpu: '2'memory: 4Girequests:cpu: '1'memory: 2Gi
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:name: svip-dubbo-manager-deployment-hpanamespace: server-svip
spec:maxReplicas: 4metrics:- resource:name: cputarget:averageUtilization: 80type: Utilizationtype: Resource- resource:name: memorytarget:averageUtilization: 80type: Utilizationtype: ResourceminReplicas: 2scaleTargetRef:apiVersion: apps/v1kind: Deploymentname: svip-dubbo-manager-deploymentcat svip-dubbo-manager-rollouts.yaml apiVersion: rollouts.kruise.io/v1alpha1
kind: Rollout
metadata:name: svip-dubbo-manager-rolloutsnamespace: server-svipannotations:rollouts.kruise.io/rolling-style: partition
spec:objectRef:workloadRef:apiVersion: apps/v1kind: Deploymentname: svip-dubbo-manager-deploymentstrategy:canary:steps:- replicas: 1- replicas: 50%- replicas: 100%rollout触发命令:
/usr/local/bin/kubectl-kruise rollout approve rollouts/svip-dubbo-manager-rollouts -n server-svip

4、最终测试验证。

k8s之Kruise Rollouts灰度发布_Pod_02