Kubernetes:限制同时部署的数量

时间:2018-02-06 16:01:42

标签: deployment kubernetes yaml

有没有办法限制Kubernetes集群一次实施的部署数量?通过滚动部署和100%正常运行时间,一次更新所有部署可能会使节点过载。

我知道可以限制每个命名空间部署的pod的数量,但我想知道是否也可以以类似的方式限制同时部署。比如说,一次最多可以进行10次部署。

我可能会对我一次发送到k8s API的部署数量进行限制,但如果有一个我可以使用的设置,那就太好了。

4 个答案:

答案 0 :(得分:1)

我想到的第一件事是使用资源limits and requests来确保您没有超载集群。这样,即使您更新了所有部署,一些pod也将处于“挂起”状态,直到其他部署成功更新为止。

答案 1 :(得分:0)

此解决方案可能会有所帮助

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 50%
  template:
    ---

在部署中设置RollingUpdate。

rollingUpdate:
  maxUnavailable: 50%

// The maximum number of pods that can be unavailable during the update.
// Value can be an absolute number (ex: 5) or a percentage of desired pods (ex: 10%).
// Absolute number is calculated from percentage by rounding down.
// This can not be 0 if MaxSurge is 0.
// Defaults to 25%.
// Example: when this is set to 30%, the old RC can be scaled down to 70% of desired pods
// immediately when the rolling update starts. Once new pods are ready, old RC
// can be scaled down further, followed by scaling up the new RC, ensuring
// that the total number of pods available at all times during the update is at
// least 70% of desired pods.

通过这种方式,您可以限制同时部署。

答案 2 :(得分:0)

我没有尝试过这个,但我认为可以使用Admission控制器来做到这一点。设置ExternalAdmissionWebhook:

https://kubernetes.io/docs/admin/extensible-admission-controllers/#external-admission-webhooks

当它收到Deployment对象的admissionReview请求时,通过API检查Deployments的计数和状态,如果超出并发Deployments的条件,则拒绝该请求。

答案 3 :(得分:0)

如果您在所有pod上设置资源请求,k8将在资源饱和的情况下对队列进行排队