Home > Software design >  how can I schedule Healthcheck in Kubernetes livenessProbe
how can I schedule Healthcheck in Kubernetes livenessProbe

Time:12-05

since we need to stop a service in the kubernetes pot at night because we need to index something in our app(we also can't stop the pod because we need to index somethin in the pod.). While Index HealthEndpoint is unreachable, Prometheus warns that the service is not live. I want to disable liveness at night.

livenessProbe:
  httpGet:
    path: /healthcheck
    port: 8080
  initialDelaySeconds: 60
  periodSeconds: 3

I've searched a lot on the internet but haven't found a solution.

CodePudding user response:

It sounds like you are trying to disable the liveness probe for your service in Kubernetes at night. To do this, you can set the initialDelaySeconds and periodSeconds values in the liveness probe to a high value (e.g. 86400 seconds, which is 24 hours) so that the probe is only performed once per day. This will prevent Prometheus from warning that the service is not live at night.

Here is an example of how you can update your liveness probe configuration to disable the probe at night:

livenessProbe:
  httpGet:
    path: /healthcheck
    port: 8080
  initialDelaySeconds: 86400
  periodSeconds: 86400

This configuration will cause the liveness probe to be performed once per day at a specific time (determined by the initialDelaySeconds value). If the probe fails, Kubernetes will not restart the pod, so the indexing process can continue without interruption.

CodePudding user response:

You have to use readinessProbe. The difference is that a service can recover from un-readiness while it cannot from failed liveness. So as long as readinessProbe reports a failure, your pod will be taken out of service, i.e. it will not receive any requests, until readinessProbe reports health again.

Note that there is no connection between livenessProbe and readinessProbe. Both are checked independent from each other. So you may and should implement different check endpoints for them. While the readiness endpoint temporarily reports unhealthiness, your liveness endpoint still has to report health. Of course, you can ommit a livenessProbe if your are comfortable with that.

  • Related