3

One of my micro service is running on Kubernetes. I would like to specify to K8s load balancer when a pod is busy because the behaviour that I get currently is not ok.

One example:

I have 8 pods running, each pod can process 1 request at a time. Each request take from 70 to 100% of the CPU core allocated to the pod. But when I send 8 requests to my application, Kubernetes does not dispatch those requests to the 8 pods but try to use only one. And since I'm blocking (via threadpool) each replica of app to use only one thread at a time, of course requests are queued for pod 1.

So my question is: How can I tell Kubernetes that POD 1 is busy and that load-balancer must dispatch request 2 to POD 2 ?

Note: For dev and test purpose I'm using Docker Desktop (Docker for Windows) on Windows 10 and kubectl.

G. Frx
  • 2,350
  • 3
  • 19
  • 31

2 Answers2

4

You have to use LivenessProbe

when a Pod will not able to handle a request its IP will be removed from Service endpoints, so no traffic will be forwarded to it.

LivenessProbe can be TCP or HTTP

prometherion
  • 2,119
  • 11
  • 22
  • 1
    @Harsh Manvar answer is more suitable: LivenessProbe & ReadinessProbe FTW – prometherion Sep 18 '19 at 11:59
  • you provided the simplest solution I was thinking big big later reading your answer in my mind comes about LivenessProbe & ReadinessProbe comes; – Harsh Manvar Sep 18 '19 at 12:49
  • @prometherion thanks for yout answer. Like you said answer from Harsh Manvar is more suitable, so I will accept this one. – G. Frx Sep 19 '19 at 08:01
3

As prometherion suggested you can use the liveness probe and also i would suggest to add the rediness probe together.

you can have a look at the official document : https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/

Sometimes, applications are temporarily unable to serve traffic. For example when, application first need to load large data or configuration files during startup.

In such cases, you don’t want to kill the application, but you don’t want to send traffic either there to pods. K8s provides readiness probes to detect and mitigate these situations. A pod with containers reporting that they are not ready does not receive traffic through Kubernetes Services.

Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • 1
    thanks for your answer. I tried readiness config but Kubernetes behaviour is still the same. Pod is correctly disabled but Kubernetes does not dispatch request to others pods.. – G. Frx Sep 18 '19 at 10:27
  • from service check labels are same with pod and service. – Harsh Manvar Sep 18 '19 at 10:52
  • Yes it is same labels – G. Frx Sep 18 '19 at 10:53
  • if container running inside pod then status of pod will be ready and service will divert traffic. Unless and untill container is not running or application end point is not giving 200 service will transfer ttraffic to pods. – Harsh Manvar Sep 18 '19 at 11:06
  • 1
    I consider that your answer is ok because it respond to my question. Unfortunately it didn't solve my problem because the problem is actually in another place, I have realized it after asking this question. – G. Frx Sep 19 '19 at 08:03
  • @FrixG great thing matter is, get to know abt the issue. – Harsh Manvar Sep 19 '19 at 08:28