Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use an HTTP POST in a preStop lifecycle hook in a Kubernetes job?

I currently have the following lifecycle hook in my kubernetes config:

lifecycle:
      preStop:
        httpGet:
          path: /path
          port: 8080

I would like to call the shutdown endpoint of spring boot actuator in this hook, but this endpoint requires a post request instead of a get. Is this in any way possible or should I define my own endpoint that shuts down my app gracefully?

Thanks for your help!

like image 658
Aletta Avatar asked Oct 17 '18 14:10

Aletta


People also ask

What is preStop in Kubernetes?

PreStop. This hook is called immediately before a container is terminated due to an API request or management event such as a liveness/startup probe failure, preemption, resource contention and others.

What is a container lifecycle hook?

Lifecycle hooks are event-aware actions performs against a container. They work like a single Kubernetes probing action, but they'll only be fired at least once per event during a container's lifetime. Right now, there are two events supported: PostStart : Executes right after a container is created.

What is lifecycle in Kubernetes?

Pods follow a defined lifecycle, starting in the Pending phase, moving through Running if at least one of its primary containers starts OK, and then through either the Succeeded or Failed phases depending on whether any container in the Pod terminated in failure.

What is Kubernetes Terminationgraceperiodseconds?

4 - Kubernetes waits for a grace period At this point, Kubernetes waits for a specified time called the termination grace period. By default, this is 30 seconds. It's important to note that this happens in parallel to the preStop hook and the SIGTERM signal. Kubernetes does not wait for the preStop hook to finish.


1 Answers

You can add an exec lifecycle hook since httpPost is not a valid one, and assuming you have curl in your containers:

lifecycle:
  preStop:
    exec:
      command: ["curl", "-XPOST", "http://URL"]
like image 94
Rico Avatar answered Oct 12 '22 04:10

Rico