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)
So, how to add these life-cycle handlers to a job or pod by Python Kubernetes?
The
preStop
andpostStart
handlers exists on the containers. You linked to the documentation for create_namespaced_job and the parameterbody
is a V1Job, and thespec
of that has atemplate
, that has aspec
of type V1PodSpec and there you find a fieldcontainer[list]
and there you find a fieldlifecycle
of type V1Lifecylce that has thepreStop
andpostStart
-handlers.The documentation can also be navigated with
kubectl explain
, e.g: