I have 10 replicas running same Java application. I would like to skip sending a request to the replica which is running full garbage collection cycle/stop the world cycle(using jvm tool interface) .
ex: 5 application are running full GC cycle , 5 have completed the GC cycle. Hence i would like to route the traffic to the pods which have completed the GC cycle .
pseduo code: 1) Load balancer recieves incoming REST request for the backend service. 2) Determine the replica's which is not in full GC cycle. 3) Use round robin to route the request to 1 of the replica's found from step 2.
Can someone help me if we can do this in kubernetes.
I have a concept for you but you need to add some part to you program. Take a look for readinessProbe
.
readinessProbe
: Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod’s IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure
. If a Container does not provide a readiness probe, the default state is Success
.
This is the example of config, you can use TCP socket as well
readinessProbe:
httpGet:
path: /healthz
port: 8181
initialDelaySeconds: 5
periodSeconds: 5
When GC starts, you stop responding by path /healthz
and kubelet marks the pod as unhealthy and wait until it becomes healthy again, in your case it will be when GC is finished.