【问题标题】:How to use kubernetes python sdk to redeploy a deployment如何使用 kubernetes python sdk 重新部署部署
【发布时间】:2020-08-13 13:00:00
【问题描述】:

版本信息:

python3.7
kubernetes==8.0.0

文档:https://github.com/kubernetes-client/python/tree/release-8.0/kubernetes

我只找到了更新API,没有找到重新部署API。

谢谢

【问题讨论】:

  • 当您说“重新部署”时,您要执行什么操作? kubectl rollout restart CLI 命令通过更改部署的 pod 规范上的注释然后使用更新 API 来工作。

标签: kubernetes kubernetes-python-client


【解决方案1】:

如果您想部分更新现有部署,请使用 PATCH method。下面是一个例子

# create an instance of the API class
api_instance = kubernetes.client.AppsV1Api(kubernetes.client.ApiClient(configuration))
name = 'name_example' # str | name of the Deployment
namespace = 'namespace_example' # str | object name and auth scope, such as for teams and projects
body = NULL # object | 
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)
dry_run = 'dry_run_example' # str | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed (optional)

try: 
    api_response = api_instance.patch_namespaced_deployment(name, namespace, body, pretty=pretty, dry_run=dry_run)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AppsV1Api->patch_namespaced_deployment: %s\n" % e)

如果您想用新部署替换现有部署,请使用PUT method。下面是一个例子

# create an instance of the API class
api_instance = kubernetes.client.AppsV1Api(kubernetes.client.ApiClient(configuration))
name = 'name_example' # str | name of the Deployment
namespace = 'namespace_example' # str | object name and auth scope, such as for teams and projects
body = kubernetes.client.V1Deployment() # V1Deployment | 
pretty = 'pretty_example' # str | If 'true', then the output is pretty printed. (optional)
dry_run = 'dry_run_example' # str | When present, indicates that modifications should not be persisted. An invalid or unrecognized dryRun directive will result in an error response and no further processing of the request. Valid values are: - All: all dry run stages will be processed (optional)

try: 
    api_response = api_instance.replace_namespaced_deployment(name, namespace, body, pretty=pretty, dry_run=dry_run)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AppsV1Api->replace_namespaced_deployment: %s\n" % e)

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 2021-08-08
    • 2022-01-13
    • 1970-01-01
    • 2023-02-16
    • 1970-01-01
    • 2017-01-08
    • 2018-09-04
    • 2016-09-14
    相关资源
    最近更新 更多