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
preStopandpostStarthandlers exists on the containers. You linked to the documentation for create_namespaced_job and the parameterbodyis a V1Job, and thespecof that has atemplate, that has aspecof type V1PodSpec and there you find a fieldcontainer[list]and there you find a fieldlifecycleof type V1Lifecylce that has thepreStopandpostStart-handlers.The documentation can also be navigated with
kubectl explain, e.g: