简体   繁体   English

Google kubernetes pods 关闭和启动

[英]Google kubernetes pods shutdown and start

We are using Google kubernetes to deploy our microservices, circlci for deployment integration, we define our k8s files inside the githup repos.我们使用 Google kubernetes 来部署我们的微服务,circlci 用于部署集成,我们在 Githup 存储库中定义了我们的 k8s 文件。

The problem we are facing is that some services are taking time on startup by loading database schema and other pre data, but google kubernetes shutdown old pods before the new pods fully started.我们面临的问题是一些服务通过加载数据库架构和其他预数据在启动时需要时间,但谷歌 kubernetes 在新 Pod 完全启动之前关闭了旧 Pod。

can we tell kubernetes somehow to wait till the new pods are fully loaded or at least to wait 10 seconds before shutdown the old pods.我们能否以某种方式告诉 kubernetes 等待新 Pod 完全加载或至少等待 10 秒才能关闭旧 Pod。

Yes, this is possible.是的,这是可能的。 Based on the description it sounds like you are using a single deployment that gets updated.根据描述,听起来您正在使用更新的单个部署。 The new pods are created and the old ones are removed before the new ones become ready.在新的 Pod 准备好之前,会创建新的 Pod 并删除旧的 Pod。

To address this, you need to have a proper readinessProbe configured or readinessGates on the pods so that the pod status only becomes ready once it actually is ready.为了解决这个问题,您需要在 pod 上配置适当的readinessProbereadinessGates ,以便 pod 状态只有在实际准备就绪后才变为准备就绪。 If you are not sure what to put as the probe, you can also define initialDelaySeconds with a guess at how much time you think the pod needs to start up.如果您不确定将什么作为探针,您还可以定义initialDelaySeconds并猜测您认为 pod 需要启动多长时间。

You should also look into using the deployment spec field for minReadySeconds as well as defining a proper deployment strategy .您还应该考虑使用minReadySeconds的部署规范字段以及定义适当的部署策略 You can ensure that the rolling update creates new pods (by defining the maxSurge field) and ensure that the old pod is not removed until the new one is ready and receiving traffic (using the maxUnavailable field = 0).您可以确保滚动更新创建新 pod(通过定义 maxSurge 字段)并确保在新 pod 准备就绪并接收流量之前不会删除旧 pod(使用 maxUnavailable 字段 = 0)。

an example would be:一个例子是:

spec:
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

This will maintain 3 working replicas at any given time.这将在任何给定时间维护 3 个工作副本。 When a new version is pushed, 1 new pod will be created with the new image.推送新版本时,将使用新映像创建 1 个新 pod。 No pods will be taken offline until the new one is in ready state.在新的 Pod 处于就绪状态之前,不会将任何 Pod 脱机。 Once it is, one of the old pods will be terminated and the cycle goes again.一旦它是,一个旧的 pod 将被终止,循环再次进行。 Feel free to change the maxSurge value to a higher number if you want the rollout to happen in one go.如果您希望一次性完成部署,请随意将maxSurge值更改为更高的数字。

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

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