简体   繁体   English

部分推出 Kubernetes Pod

[英]Partially Rollout Kubernetes Pods

I have 1 node with 3 pods.我有 1 个节点和 3 个 pod。 I want to rollout a new image in 1 of the three pods and the other 2 pods stay with the old image.我想在三个 pod 中的一个中推出新图像,而其他 2 个 pod 保留旧图像。 Is it possible?是否可以?

Second question.第二个问题。 I tried rolling out a new image that contains error and I already define the maxUnavailable.我尝试推出一个包含错误的新图像,并且我已经定义了 maxUnavailable。 But kubernetes still rollout all pods.但是 kubernetes 仍然推出所有 pod。 I thought kubernetes will stop rolling out the whole pods, once kubernetes discover an error in the first pod.我认为一旦 kubernetes 在第一个 pod 中发现错误,kubernetes 将停止推出整个 pod。 Do we need to manually stop the rollout?我们是否需要手动停止发布?

Here is my deployment script.这是我的部署脚本。

# Service setup
apiVersion: v1
kind: Service
metadata:
  name: semantic-service
spec:
  ports:
    - port: 50049
  selector:
    app: semantic
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: semantic-service
spec:
  selector:
    matchLabels:
      app: semantic
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: semantic
    spec:
      containers:
      - name: semantic-service
        image: something/semantic-service:v2

As @David Maze wrote in the comment, you can consider using canary where it is possible distinguish deployments of different releases or configurations of the same component with multiple labels and then track these labels and point to different releases, more information about Canary deployments can be find here .正如@David Maze 在评论中所写的那样,您可以考虑使用canary ,它可以区分不同版本的部署或具有多个标签的同一组件的配置,然后跟踪这些标签并指向不同的版本,有关Canary deployments更多信息可以在在这里找到。 Another way how to achieve your goal can be Blue/Green deployment in case if you want to use two different environments identical as possible with a comprehensive way to switch between Blue/Green environments and rollback deployments at any moment of time.实现目标的另一种方法是蓝/绿部署,以防您想使用两个尽可能相同的不同环境,并通过全面的方式在蓝/绿环境和随时回滚部署之间切换。

Answering the second question depends on what kind of error a given image contains and how Kubernetes identifies this issue in the Pod, as maxUnavailable: 1 parameter states maximum number of Pods that can be unavailable during update.回答第二个问题取决于给定图像包含的错误类型以及 Kubernetes 如何在 Pod 中识别此问题,如maxUnavailable: 1参数表示更新期间可能不可用的最大 Pod 数。 In the process of Deployment update within a cluster deployment controller creates a new Pod and then delete the old one assuming that the number of available Pods matches rollingUpdate strategy parameters.在集群部署控制器内的部署更新过程中,假设可用 Pod 的数量与rollingUpdate策略参数匹配,则创建一个新的 Pod,然后删除旧的。

Additionally, Kubernetes uses liveness/readiness probes to check whether the Pod is ready (alive) during deployment update and leave the old Pod running until probes have been successful on the new replica.此外,Kubernetes 使用活性/就绪探针在部署更新期间检查 Pod 是否准备好(活动),并使旧 Pod 保持运行状态,直到probes在新副本上成功。 I would suggest checking probes to identify the status of the Pods when deployment tries rolling out updates across you cluster Pods.当部署尝试跨集群 Pod 推出更新时,我建议检查probes以识别 Pod 的状态。

Regarding question 1:关于问题1:

I have 1 node with 3 pods.我有 1 个节点和 3 个 pod。 I want to rollout a new image in 1 of the three pods and the other 2 pods stay with the old image.我想在三个 pod 中的一个中推出新图像,而其他 2 个 pod 保留旧图像。 Is it possible?是否可以?

Answer:回答:
Change your maxSurge in your strategy to 0 :将您的策略​​中的maxSurge更改为0

replicas: 3
strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1 <------ From the 3 replicas - 1 can be unavailable
      maxSurge: 0       <------ You can't have more then the 3 replicas of pods at a time

Regarding question 2:关于问题2:

I tried rolling out a new image that contains error and I already define the maxUnavailable.我尝试推出一个包含错误的新图像,并且我已经定义了 maxUnavailable。 But kubernetes still rollout all pods.但是 kubernetes 仍然推出所有 pod。 I thought kubernetes will stop rolling out the whole pods, once kubernetes discover an error in the first pod.我认为一旦 kubernetes 在第一个 pod 中发现错误,kubernetes 将停止推出整个 pod。 Do we need to manually stop the rollout?我们是否需要手动停止发布?

A ) In order for kubernetes to stop rolling out the whole pods - Use minReadySeconds to specify how much time the pod that was created should be considered ready (use liveness / readiness probes like @Nick_Kh suggested). A )为了让 kubernetes 停止推出整个 pod - 使用minReadySeconds指定应将创建的 pod 视为ready (使用@Nick_Kh 建议的活性/就绪探针)。
If one of the probes had failed before the interval of minReadySeconds has finished then the all rollout will be blocked.如果其中一个探测在minReadySeconds间隔结束之前失败,则所有推出将被阻止。

So with a combination of maxSurge = 0 and the setup of minReadySeconds and liveness / readiness probes you can achieve your desired state: 3 pods: 2 with the old image and 1 pod with the new image .因此,结合maxSurge = 0以及minReadySecondsminReadySeconds / readiness 探针的设置,您可以实现所需的状态: 3 个 pod:2 个带有旧图像,1 个 pod 带有新图像

B ) In case of A - you don't need to stop the rollout manually. B )在 A 的情况下 - 您不需要手动停止推出。

But in cases when you will have to do that, you can run:但如果你必须这样做,你可以运行:

$ kubectl rollout pause deployment <name>

Debug the non functioning pods and take the relevant action.调试不起作用的 Pod 并采取相关操作。

If you decide to revert the rollout you can run:如果您决定恢复推出,您可以运行:

$ kubectl rollout undo deployment <name> --to-revision=1

(View revisions with: $ kubectl rollout history deployment <name> ). (查看修订: $ kubectl rollout history deployment <name> )。

Notice that after you pause d the rollout you need to resume it with:请注意,在pause发布后,您需要使用以下命令resume它:

$ kubectl rollout resume deployment <name>

Even if you decide to undo and return to previous revision.即使您决定undo并返回到以前的修订版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM