一、应用层面的升级策略

1.1 基于K8S的应用升级策略

可在 Deployment.spec.strategy 中设置升级策略有两种

  • Recreate:在创建新策略之前删除所有容器集,升级期间服务不可用,适合停机升级;
  • RollingUpdate(默认):滚动升级,可以设置升级策略,升级期间服务可用;

注意点:

Recreate

Kubernetes 先终止当前版本中的所有容器,然后在旧容器删除时同时启动所有新容器,不会有 2 种版本容器同时运行,这对服务使用者来说更简单。

优点:不存在新老版本共存;

缺点:可能存在服务某段时间服务不可用;

特点:所有容器集一起Terminating,一起Pending,一起ContainerCreating,一起 Running。

场景:当发布到开发/测试环境的时候,重建或者滚动更新通常是一个不错的选择。

RollingUpdate

Deployment控制器的滚动更新操作并非在同一个ReplicaSet控制器对象下删除并创建 Pod资源,而是将它们分置于两个不同的控制器之下:旧控制器的Pod对象数量不断减少的同时,新控制器的Pod对象数量不断增加,直到旧控制器不再拥有Pod对象,而新控制器的副本数量变得完全符合期望值为止;

优点:不存在某段时间内服务不可用;

缺点:切换过程中,存在pod新老版本共存;

特点:默认是滚动更新,缺省是滚动更新(核心参数);

  • maxUnavailable:滚动升级时允许的最大unavailable的pod数量,可以是整数或者百分比(默认25%),这个值越小,越能保证服务稳定,更新越平滑;
  • maxSurge:滚动升级时先启动的pod数量,可以是整数或者百分比(默认 25%),这个值调的越大,副本更新速度越快;

场景:在生产环境,滚动更新发布比较合适,但是新版本的提前测试是非常有必要的。

Recreate测试验证

# 创建ns
[root@master01 1]# k create ns study

# 创建deploy模板
[root@master01 1]# k create deploy nginx-deployment --image=registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2 -r=5 --dry-run=client -oyaml > nginx-recreate.yaml

# 创建svc模板
[root@master01 1]# k create svc nodeport nginx-service  --tcp=80:80 --node-port=30080 --dry-run=client -oyaml > nginx-service.yaml

# 定义yaml文件
[root@master01 1]# vim  nginx-recreate.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
  namespace: study
spec:
  replicas: 3
  revisionHistoryLimit: 4 #限制了修订版本历史的数量为4
  selector:
    matchLabels:
      app: nginx
  strategy:   #定义部署策略这里是Recreate类型表示在更新时先删除旧的Pod然后再创建新的Pod
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: study
spec:
  ports:
  - nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort

# 应用
[root@master01 1]# kaf nginx-recreate.yaml

# 查看pod
[root@master01 1]# kgp -n study -owide
NAME                                READY   STATUS    RESTARTS   AGE    IP               NODE       NOMINATED NODE   READINESS GATES
nginx-deployment-7574485f4c-5n5lr   1/1     Running   0          3m7s   172.21.231.157   node02     <none>           <none>
nginx-deployment-7574485f4c-c69mv   1/1     Running   0          3m7s   172.29.55.25     node01     <none>           <none>
nginx-deployment-7574485f4c-thh2h   1/1     Running   0          3m7s   172.18.71.11     master03   <none>           <none>

# 查看svc
[root@master01 1]# kg svc -n study
NAME            TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
nginx-service   NodePort   10.0.32.111   <none>        80:30080/TCP   4m42s

# 新起一个窗口实时监控版本变更
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30080 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 24 Dec 2024 08:56:34 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
...
...

# 模拟服务比如升级nginx版本至1.21.6
[root@master01 1]# vim  nginx-recreate.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
  namespace: study
spec:
  replicas: 3
  revisionHistoryLimit: 4 #限制了修订版本历史的数量为4
  selector:
    matchLabels:
      app: nginx
  strategy:   #定义部署策略这里是Recreate类型表示在更新时先删除旧的Pod然后再创建新的Pod
    type: Recreate
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.21.6
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: study
spec:
  ports:
  - nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort

# 重新应用
[root@master01 1]# kaf nginx-recreate.yaml

# 验证,观察到pod在创建过程中会中断
[root@master01 istio]# while sleep 0.5;do curl 192.168.1.65:30080 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Mon, 06 Nov 2023 13:36:13 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
...
...
curl: (7) Failed connect to 10.0.0.60:30080; No route to host
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
curl: (7) Failed connect to 10.0.0.60:30080; Connection refused
HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Tue, 24 Dec 2024 08:58:35 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
...
...

# 环境复原
[root@master01 1]# k delete -f nginx-recreate.yaml

RollingUpdate测试验证

# 创建ns
[root@master01 1]# k create ns study

# 创建deploy模板
[root@master01 1]# k create deploy nginx-deployment --image=registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2 -r=5 --dry-run=client -oyaml > nginx-rolling.yaml

# 创建svc模板
[root@master01 1]# k create svc nodeport nginx-service  --tcp=80:80 --node-port=30080 --dry-run=client -oyaml > nginx-rolling-svc.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-rolling.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
  namespace: study
spec:
  replicas: 3
  revisionHistoryLimit: 4 #限制了修订版本历史的数量为4
  selector:
    matchLabels:
      app: nginx
  strategy:   #定义部署策略这里是RollingUpdate类型(默认类型)
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25% #最多允许不可用的Pod数目这里设置为25%
      maxSurge: 25%       #允许的最大增加Pod数目这里设置为25%
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: study
spec:
  ports:
  - nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort

# 应用
[root@master01 1]# kaf nginx-rolling.yaml

# 新起一个窗口实时监控版本变更
[root@master01 istio]# while sleep 0.5;do curl 10.0.0.60:30080 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 24 Dec 2024 09:02:07 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

...
...

# 模拟服务比如升级nginx版本至1.21.6
[root@master01 1]# vim  nginx-rolling.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
  namespace: study
spec:
  replicas: 3
  revisionHistoryLimit: 4 #限制了修订版本历史的数量为4
  selector:
    matchLabels:
      app: nginx
  strategy:   #定义部署策略这里是RollingUpdate类型
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25% #最多允许不可用的Pod数目这里设置为25%
      maxSurge: 25%       #允许的最大增加Pod数目这里设置为25%
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.21.6
        name: nginx
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: study
spec:
  ports:
  - nodePort: 30080
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort

# 重新应用
[root@master01 1]# kaf nginx-rolling.yaml

# 验证,观察到pod在创建过程中不会中断
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30080 -I;done
...
...
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Mon, 06 Nov 2023 14:41:17 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Mon, 06 Nov 2023 14:41:17 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Mon, 06 Nov 2023 14:41:18 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Mon, 06 Nov 2023 14:41:18 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Mon, 06 Nov 2023 14:41:19 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Mon, 06 Nov 2023 14:41:19 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
...
...

# 环境复原
[root@master01 1]# k delete -f nginx-rolling.yaml

1.2 蓝绿发布

蓝绿部署:蓝绿部署,service-selector 选择器,一键切换;

核心:先将v1,v2都启动起来,然后一键切换(保证deployment name不同即可做到)

滚动更新 的 缺点 是:切换过程中,可能会出现访问到 v1 的情况;

重新创建 的 缺点 是:切换过程中,可能出现服务端无响应的情况;

蓝绿部署就是滚动更新提供的另一种方案,就是v2都启动之后,然后一键切过去,不存在切换过程中访问到v1的情况,可以无缝升级,可以无缝回退。

蓝绿部署 = 无缝切换 + 不会无响应

测试验证

# 创建ns
[root@master01 1]# k create ns study

# 创建deploy模板
[root@master01 1]# k create deploy nginx-blue-deployment --image=registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2 -r=5 --dry-run=client -oyaml > nginx-blue.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-blue.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-blue
  name: nginx-blue-deployment
  namespace: study
spec:
  replicas: 4
  revisionHistoryLimit: 4
  selector:
    matchLabels:
      app: nginx-blue
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    metadata:
      labels:
        app: nginx-blue
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2
        name: nginx-blue
        ports:
        - containerPort: 80

# 应用
[root@master01 1]# kaf nginx-blue.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-green.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-green
  name: nginx-green-deployment
  namespace: study
spec:
  replicas: 4
  revisionHistoryLimit: 4
  selector:
    matchLabels:
      app: nginx-green
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    metadata:
      labels:
        app: nginx-green
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.21.6
        name: nginx-green
        ports:
        - containerPort: 80

# 应用
[root@master01 1]# kaf nginx-green.yaml

# 查看
[root@master01 1]# kgp -n study
NAME                                      READY   STATUS    RESTARTS   AGE
nginx-blue-deployment-5d59c7b647-2h8wl    1/1     Running   0          58s
nginx-blue-deployment-5d59c7b647-mtgls    1/1     Running   0          58s
nginx-blue-deployment-5d59c7b647-pcd7j    1/1     Running   0          58s
nginx-blue-deployment-5d59c7b647-zwb8b    1/1     Running   0          58s
nginx-green-deployment-676c555687-hlhp7   1/1     Running   0          12s
nginx-green-deployment-676c555687-ppl7l   1/1     Running   0          12s
nginx-green-deployment-676c555687-q69rl   1/1     Running   0          12s
nginx-green-deployment-676c555687-qjxzv   1/1     Running   0          12s

# 创建svc模板
[root@master01 1]# k create svc nodeport nginx-bluegreen-service  --tcp=80:80 --node-port=30090 --dry-run=client -oyaml > nginx-bluegreen-svc.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-bluegreen-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-bluegreen-service
  namespace: study
spec:
  ports:
  - nodePort: 30090
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-blue
  type: NodePort

# 应用
[root@master01 1]# kaf nginx-bluegreen-svc.yaml

# 新起一个窗口实时监控版本变更,目前版本为1.14.2
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30090 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 04:50:42 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
...
...

# 切换版本修改app=nginx-green
[root@master01 1]# vim nginx-bluegreen-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-bluegreen-service
  namespace: study
spec:
  ports:
  - nodePort: 30090
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-green
  type: NodePort

# 重新应用
[root@master01 1]# kaf nginx-bluegreen-svc.yaml

# 在新起一个窗口实时监控版本变更,目前版本直接变为1.21.6
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30090 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 04:50:42 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Tue, 07 Nov 2023 04:55:38 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
...
...

# 回滚版本修改app=nginx-blue
[root@master01 1]# vim nginx-bluegreen-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-bluegreen-service
  namespace: study
spec:
  ports:
  - nodePort: 30090
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-blue
  type: NodePort

# 重新应用
[root@master01 1]# kaf nginx-bluegreen-svc.yaml

# 在新起一个窗口实时监控版本变更,目前版本由1.21.6回滚到1.14.2
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30090 -I;done
HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Tue, 07 Nov 2023 04:55:38 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 04:50:42 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
...
...

# 环境复原
[root@master01 1]# k delete -f  nginx-bluegreen-svc.yaml
[root@master01 1]# k delete -f  nginx-blue.yaml
[root@master01 1]# k delete -f  nginx-green.yaml

1.3 金丝雀发布

金丝雀发布一般是先发一个新版本应用,或者一个小比例,例如1个pod的新应用,主要做流量验证用,也称为金丝雀 (Canary) 测试,国内常称灰度测试。

以前旷工下矿前,会先放一只金丝雀进去用于探测洞里是否有有毒气体,看金丝雀能否活下来,金丝雀发布由此得名。

简单的金丝雀测试一般通过手工测试验证,复杂的金丝雀测试需要比较完善的监控基础 设施配合,通过监控指标反馈,观察金丝雀的健康状况,作为后续发布或回退的依据。

如果金丝测试通过,则把剩余的 V1 版本全部升级为 V2 版本。如果金丝雀测试失败,则直接回退金丝雀,发布失败。

验证:

v1:当前线上V1版本(副本3个)

v2:未来线上V2新版本(副本1个)

需求 :v1作为当前线上运行版本,保持75%流量;新版本25%流量作为验证,一旦出现问题,随时回滚删除新版本pod;

# 创建ns
[root@master01 1]# k create ns study

# 创建svc模板
[root@master01 1]# k create svc nodeport nginx-bluegreen-service  --tcp=80:80 --node-port=30090 --dry-run=client -oyaml > nginx-canary-svc.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-canary-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-canary-service
  namespace: study
spec:
  ports:
  - nodePort: 30100
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-canary
  type: NodePort

# 应用
[root@master01 1]# kaf nginx-canary-svc.yaml

# 创建deploy模板
[root@master01 1]# k create deploy nginx-v1 --image=registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2 -r=5 --dry-run=client -oyaml > nginx-canary-v1.yaml

# 定义yaml文件
[root@master01 1]# vim nginx-canary-v1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v1
  namespace: study
spec:
  replicas: 3
  revisionHistoryLimit: 4
  selector:
    matchLabels:
      app: nginx-canary
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    metadata:
      labels:
        app: nginx-canary
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.14.2
        name: nginx-canary
        ports:
        - containerPort: 80

# 应用
[root@master01 1]# kaf nginx-canary-v1.yaml

# 在新起一个窗口实时监控版本变更,此时版本为1.14.2
[root@master01 ~]# while sleep 0.5;do curl 10.0.0.60:30100 -I;done
HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 05:25:11 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes
...
...

# 定义yaml文件
[root@master01 1]# vim nginx-canary-v2.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-v2
  namespace: study
spec:
  replicas: 1
  revisionHistoryLimit: 4
  selector:
    matchLabels:
      app: nginx-canary
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  template:
    metadata:
      labels:
        app: nginx-canary
    spec:
      containers:
      - image: registry.cn-hangzhou.aliyuncs.com/zq-demo/nginx:1.21.6
        name: nginx-canary
        ports:
        - containerPort: 80

# 应用
[root@master01 1]# kaf nginx-canary-v2.yaml

# 监控版本变更,默认为轮询算法即3次老版本1.14.21次新版本1.21.6
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 05:25:10 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 05:25:11 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 07 Nov 2023 05:25:11 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Apr 2019 01:08:42 GMT
Connection: keep-alive
ETag: "5cad421a-264"
Accept-Ranges: bytes

HTTP/1.1 200 OK
Server: nginx/1.21.6
Date: Tue, 07 Nov 2023 05:25:12 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 25 Jan 2022 15:03:52 GMT
Connection: keep-alive
ETag: "61f01158-267"
Accept-Ranges: bytes
...
...

# 环境复原
[root@master01 1]# k delete -f  nginx-canary-svc.yaml
[root@master01 1]# k delete -f  nginx-canary-v1.yaml
[root@master01 1]# k delete -f  nginx-canary-v2.yaml

1.4 总结

  • 当发布到开发/测试环境时,重新创建或升级部署通常是一个不错的选择。

  • 生产方面,蓝/绿部署通常很合适。

  • 需要对新平台/新功能进行适当的引流验证,选择金丝雀版本。