I have one application which servers for REST request and also is listening on a Kafka topic. I deployed the application to Kubernetes and configure the readiness probe like this
readinessProbe:
exec:
command:
- cat
- /tmp/healthy
initialDelaySeconds: 5
periodSeconds: 5
basically following the instruction from [configure-liveness-readiness-startup-probes]
After deployment is done, I can see the pod readiness probe fails
Readiness probe failed: cat: can't open '/tmp/healthy': No such file or directory
That is expected. Then I sent a kafka message to the topic . I observed that
1) the kafka message has been consumed by my application and saved to database.
2) the rest api can't be accessed.
I assumed if the pod's readiness probe is failed, the application can neither receive kafka message nor the rest request. But why in my test, the REST request and Kafka message are handled differently.
According to the Kubernete documentation:
The kubelet uses readiness probes to know when a Container is ready to start accepting traffic
But it doesn't say clearly what kind of traffic it really means. Does kubernetes only restrict the http traffic to the pod if readiness probe failes but not restrict tcp traffic (as Kafka is working over tcp)?
My actual intention is to make my service application (kafka consumer) able to control when to receive kafka messages (and REST request as well). E.g. if there is heavy opertion, my service will delete the /tmp/healthy file and thus make the pod not ready for recieving kafka message and Rest request. When the heavy operation is finished, the app write the healthy file to make the pod ready for receiving message.
Some more information, in my test, the kubernetes version is v1.14.3 and kafka broker is running in a separated vm outside of kubernetes.
kubectl get services
shows there is kubernetes with type ClusterIP. – Shenghua Liuip_of_service_vm:9092
. The ip of the service vm is just normal IPV4 address. My consumer app is using the same format for kafka Consumer configuration. Producer app and consumer app are running in different Pods. – Shenghua Liu