pykube - RollingUpdater规模副本

时间:2017-01-08 21:53:49

标签: python kubernetes

使用pykube模块https://github.com/kelproject/pykube

有谁知道如何利用RollingUpdate#scale_up函数来增加部署副本?

我很难从代码库中找到解决方法。

3 个答案:

答案 0 :(得分:1)

管理要解决此问题 - 将副本增加到3,您将执行以下操作:

deployments = pykube.Deployment.objects(kubernetesApi).filter(namespace="my-namespace")

for dp in deployments:
    if dp.obj["metadata"]["name"] == "my-deployment":
        dp.replicas = 3
        pykube.Deployment(kubernetesApi, dp.obj).update()

答案 1 :(得分:1)

以下方法更简单:

import pykube
import operator

api = pykube.HTTPClient(pykube.KubeConfig.from_file("/root/.kube/config"))

deployment = pykube.Deployment.objects(api).filter(namespace="kube-system").get(name="test-busybox")

deployment.replicas = 1
deployment.update()

答案 2 :(得分:0)

@ eggsy84的答案会有效但不优雅,因为你不需要检查所有Deployment来更新。

如果您想使用pykube进行更新,请参阅实际示例。

import pykube
import operator

api = pykube.HTTPClient(pykube.KubeConfig.from_file("~/.kube/config"))

name = "ms-999-ear2-071625"
deployment_obj = {
          "apiVersion": "extensions/v1beta1",
          "kind": "Deployment",
          "metadata": {
              "name": name,
          }
      }

deployment = pykube.Deployment(api, deployment_obj)
deployment.update()
deployment.replicas = 2
deployment.update()