全球即时:Deployment滚动更新策略Recreate

腾讯云   2023-04-29 16:37:37


(资料图)

Recreate策略

Recreate策略是另一种滚动更新策略,它会先删除旧的Pod,然后再创建新的Pod。在进行滚动更新时,所有的Pod都会被同时停止,然后全部替换为新的Pod。Recreate策略的优点是可以避免新旧Pod的共存问题,但会在升级期间中断服务。

下面是一个Recreate策略的示例:

apiVersion: apps/v1kind: Deploymentmetadata:  name: nginx-deployment  labels:    app: nginxspec:  replicas: 4  selector:    matchLabels:      app: nginx  template:    metadata:      labels:        app: nginx    spec:      containers:        - name: nginx          image: nginx:1.16          ports:            - containerPort: 80          livenessProbe:            httpGet:              path: /              port: 80            initialDelaySeconds: 10            periodSeconds: 5            timeoutSeconds: 2            failureThreshold: 3          readinessProbe:            httpGet:              path: /              port: 80            initialDelaySeconds: 10            periodSeconds: 5            timeoutSeconds: 2            failureThreshold: 3          lifecycle:            preStop:              exec:                command: ["/usr/sbin/nginx","-s","quit"]

这是一个创建了4个nginx Pod的Deployment对象,每个Pod中的nginx容器都有一个存活性探针和就绪性探针,并且在终止Pod之前执行preStop钩子,使用/usr/sbin/nginx -s quit命令关闭nginx服务器。这确保了nginx在关闭之前可以正常完成当前正在处理的请求。