Home > Software engineering >  can K8S readiness probe control kafka consume?
can K8S readiness probe control kafka consume?

Time:01-06

I need consume messages from Kafka. Application deployed in k8s pod. If I create some readiness probe to check pre-initialization steps are done or not, will k8s be able to control the consume to start consume after that?
I know readiness probe can help to control allocate outside request to pod before it is up. But not sure will it be able to control request initiated from pod.

CodePudding user response:

Kubernetes uses liveness and readiness probes to find out if your pods are healthy. If the liveness probe fails, Kubernetes will kill the container and automatically restart it if the restart policy is set accordingly. If the readiness probe fails then Kubernetes will remove the pod from serving requests through a service. But,it doesn't necessarily mean kafka is ready to consume messages. kafka can not consume messages until broker is unfenced. I would suggest you to manually handle this.

CodePudding user response:

You previously tagged .

You can define a custom healthcheck via Actuator that uses Kafka AdminClient to determine Kafka cluster / topic health. Then k8s will probe an HTTP health endpoint to determine whether to restart any unhealthy pod.

But that has nothing to do with runtime execution of the Kafka consumer. You'll need to explicitly check connectivity / health before starting any consumer threads.

Alternatively, there's plenty of serverless k8s tools with Kafka integration, such as Knative that also provide consumer capabilities

  • Related