0

version info:

python3.7
kubernetes==8.0.0

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

I only found the update API, not the redeploy API。

thanks

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
liyao
  • 5
  • 2
  • When you say "redeploy", what action are you trying to perform? The `kubectl rollout restart` CLI command works by changing an annotation on the deployment's pod spec and then using the update API. – David Maze Aug 13 '20 at 11:29

1 Answers1

1

If you want to partially update an existing deployment use PATCH method. An example below

# 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)

If you want to replace the existing deployment with a new deployment use PUT method. An example below

# 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)
Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107