How to create a job with postStart and preStop handlers by python kubernetes

567 views Asked by At

In the create_namespaced_job method there is no parameter that exists to define preStop and postStart handlers.

V1Job create_namespaced_job(namespace, body, pretty=pretty, dry_run=dry_run, field_manager=field_manager)

Source.

So, how to add these life-cycle handlers to a job or pod by Python Kubernetes?

1

There are 1 answers

0
Jonas On

In the create_namespaced_job method there is no parameter that exists to define preStop and postStart handlers.

The preStop and postStart handlers exists on the containers. You linked to the documentation for create_namespaced_job and the parameter body is a V1Job, and the spec of that has a template, that has a spec of type V1PodSpec and there you find a field container[list]and there you find a field lifecycle of type V1Lifecylce that has the preStop and postStart-handlers.

The documentation can also be navigated with kubectl explain, e.g:

kubectl explain podTemplate.template.spec.containers.lifecycle