简体   繁体   English

Kubernetes中的程序化负载平衡

[英]Programmatic load balancing in kubernetes

I have 10 replicas running same Java application. 我有10个运行相同Java应用程序的副本。 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) . 我想跳过向正在运行完整垃圾回收周期/停止世界周期的副本的发送请求(使用jvm工具界面)。

ex: 5 application are running full GC cycle , 5 have completed the GC cycle. 例如:5个应用程序正在运行完整的GC周期,5个应用程序已完成GC周期。 Hence i would like to route the traffic to the pods which have completed the GC cycle . 因此,我想将流量路由到已完成GC周期的Pod。

pseduo code: 1) Load balancer recieves incoming REST request for the backend service. pseduo代码:1)负载平衡器接收后端服务的传入REST请求。 2) Determine the replica's which is not in full GC cycle. 2)确定不在完整GC周期中的副本。 3) Use round robin to route the request to 1 of the replica's found from step 2. 3)使用轮询将请求路由到步骤2中找到的副本中的1个。

Can someone help me if we can do this in kubernetes. 如果我们可以在kubernetes中做到这一点,有人可以帮我吗。

I have a concept for you but you need to add some part to you program. 我为您提供了一个概念,但是您需要在程序中添加一些部分。 Take a look for readinessProbe . 看一看readinessProbe

readinessProbe : Indicates whether the Container is ready to service requests. readinessProbe :指示容器是否准备好服务请求。 If the readiness probe fails, the endpoints controller removes the Pod's IP address from the endpoints of all Services that match the Pod. 如果就绪探针失败,则端点控制器将从与Pod匹配的所有服务的端点中删除Pod的IP地址。 The default state of readiness before the initial delay is Failure . 初始延迟之前的默认就绪状态为Failure If a Container does not provide a readiness probe, the default state is Success . 如果容器未提供就绪探测器,则默认状态为Success

This is the example of config, you can use TCP socket as well 这是配置的示例,您也可以使用TCP套接字

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. 当GC启动时,您将停止通过路径/healthz响应,并且kubelet将吊舱标记为不正常,然后等待其再次变得健康,在您的情况下,它将是GC完成时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM