这里是一些链接

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-deployment
  namespace: server-svip
  labels:
    app: svip-dubbo-manager
spec:
  replicas: 2
  selector:
    matchLabels:
      app: svip-dubbo-manager
  template:
    metadata:
      labels:
        app: svip-dubbo-manager
    spec:
      topologySpreadConstraints: # 拓扑分布约束
      - maxSkew: 1 # 允许的最大偏差为 1
        topologyKey: kubernetes.io/hostname # 拓扑键为节点的主机名
        whenUnsatisfiable: DoNotSchedule # 如果无法满足约束条件,则不调度 Pod
        labelSelector: # 选择带有以下标签的 Pod
          matchLabels:
            app: svip-dubbo-manager
      imagePullSecrets:
      - name: harbor-regcred
      containers:
      - name: svip-dubbo-manager
        image: xxx/svip/production/svip-dubbo-manager:v24.11.06.1840_20240828_ack
        imagePullPolicy: Always # 添加这一行,确保总是重新拉取镜像
        lifecycle:
          postStart:
            exec:
              command:
                - /bin/sh
                - '-c'
                - /usr/sbin/crond
        env:
        - name: aliyun_logs_ack-prod-java-svip-manager-dubbo
          value: /data2/logs/svip-dubbo-manager/newcomlog.log
        ports:
        - containerPort: 20884
        livenessProbe:
          tcpSocket:
            port: 33302
          initialDelaySeconds: 150
          periodSeconds: 10
        readinessProbe:
          tcpSocket:
            port: 33302
          initialDelaySeconds: 90
          periodSeconds: 30
        resources:
          limits:
            cpu: '2'
            memory: 4Gi
          requests:
            cpu: '1'
            memory: 2Gi
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: svip-dubbo-manager-deployment-hpa
  namespace: server-svip
spec:
  maxReplicas: 4
  metrics:
    - resource:
        name: cpu
        target:
          averageUtilization: 80
          type: Utilization
      type: Resource
    - resource:
        name: memory
        target:
          averageUtilization: 80
          type: Utilization
      type: Resource
  minReplicas: 2
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: svip-dubbo-manager-deployment



cat svip-dubbo-manager-rollouts.yaml 

apiVersion: rollouts.kruise.io/v1alpha1
kind: Rollout
metadata:
  name: svip-dubbo-manager-rollouts
  namespace: server-svip
  annotations:
    rollouts.kruise.io/rolling-style: partition
spec:
  objectRef:
    workloadRef:
      apiVersion: apps/v1
      kind: Deployment
      name: svip-dubbo-manager-deployment
  strategy:
    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