Kubernetes滚动更新而不会停机吗? [英] Kubernetes rolling update without downtime?

查看:135
本文介绍了Kubernetes滚动更新而不会停机吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#scaling-a-statefulset ,我想问一下如何实现零停机滚动更新?我想这是最低要求:

According to https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#scaling-a-statefulset, I would like to ask how to achieve zero-downtime rolling update? I guess here are the minimum requirements:

(1).spec.updateStrategy设置为RollingUpdate

(1) .spec.updateStrategy set to RollingUpdate

(2).spec.podManagementPolicy设置为OrderedReady

(2) .spec.podManagementPolicy set to OrderedReady

(3).spec.replicas设置为2

(3) .spec.replicas set to 2

是吗?而且我假设当更新以相反的顺序进行时,所有到StatefulSet的流量都由序号较低的Pod服务?

Is that right? And I assume that when update is happening in reverse order, all traffic to the StatefulSet is served by the pods with lower ordinal number?

推荐答案

是的,对于statefulsets升级,停机时间为零,您应该提到的所有要点:

Yes to have have zero downtime for statefulsets upgrade, you should have all the points mentioned:

  1. .spec.updateStrategy设置为RollingUpdate
  2. .spec.podManagementPolicy设置为OrderedReady,默认情况下为OrderedReady
  3. .spec.replicas设置为最小值2.
  1. .spec.updateStrategy set to RollingUpdate
  2. .spec.podManagementPolicy set to OrderedReady which is by default OrderedReady
  3. .spec.replicas set to minimum 2.

另外,您需要确保状态集没有停机的事情是正确的readiness探针集. readiness探针告诉kubernetes控制器管理器该Pod已准备好处理请求,您可以开始向其发送请求.

Another, thing you need to make sure your statefulset doesn't have downtime is proper readiness probe set. The readiness probe tells kubernetes controller manager that this pod is ready to serve request and you can start sending the requests to it.

进行零停机时间升级时非常重要的原因是,假设您有两个副本的statefulset,并且在没有准备就绪探针集的情况下开始了滚动升级. kubernetes将以相反的顺序删除容器,使其处于运行状态,并将其标记为就绪,然后终止另一个容器.现在让我们说您的容器流程在那个时候没有出现,因为没有一个容器可以满足请求,因为一个容器尚未完全准备就绪,而kubernetes已经终止了另一个容器进行升级,因此导致数据丢失.

The reason it is very important while doing zero downtime upgrade is lets say you have two replica's of statefulset and you started rolling upgrade without readiness probe set. The kubernetes will delete the pod in reverse order and make it come to running state and mark it as ready and terminate another pod. Now lets say your container process didn't come up in that time there will be no pod to serve the requests, because one pod is not completely ready yet and kubernetes has terminated another pod for upgrade process and hence the data loss.

readinessProbe:
  httpGet:
    path: /
    port: 80
  initialDelaySeconds: 5
  periodSeconds: 5
  successThreshold: 1

在我的情况下,我使用以下json代码片段滚动更新statefulsets:

The following json snippet I use for rolling update of statefulsets in my case:

 "spec": {
         "containers": [
           {
             "name": "md",
             "image": "",
             "imagePullPolicy": "IfNotPresent",
             "command": [
               "/bin/sh",
               "-c"
             ],
             "args": [
               "chmod -R 777 /logs/; /on_start.sh"
             ],
             "readinessProbe": {
                "exec": {
                   "command": [
                      "cat",
                      "/tmp/ready.txt"
                   ]
                 },
                 "failureThreshold": 10,
                 "initialDelaySeconds": 5,
                 "periodSeconds": 5,
                 "successThreshold": 1,
                 "timeoutSeconds": 1
             },
             "securityContext": {
               "privileged": true
             }
      }

这是您可以在statefulset容器中设置就绪探针的方法.我将就绪探针设置为linux command,如果您使用http探针,则将有所不同.

This is how you can setup readiness probe in your statefulset containers. I am setting readiness probe as linux command, if you have http probe then it will be different.

这篇关于Kubernetes滚动更新而不会停机吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆