如何使用kubernetes python SDK重新部署

问题描述

版本信息:

python3.7
kubernetes==8.0.0

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

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

谢谢

解决方法

如果要部分更新现有部署,请使用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',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,dry_run=dry_run)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling AppsV1Api->replace_namespaced_deployment: %s\n" % e)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...