简体   繁体   English

AKS LoadBalancer仅将流量发送到一个Pod

[英]AKS LoadBalancer only sends traffic to one pod

I have a service configured as a LoadBalancer running on a five-node cluster running 1.9.11. 我有一个配置为在运行1.9.11的五节点群集上运行的LoadBalancer的服务。 The LoadBalancer sits in front of three pods running an ASP.NET Core web application (that in turn talks to a NATS message queue from which a listener retrieves messages and saves them to an Azure SQL database). LoadBalancer位于运行ASP.NET Core Web应用程序的三个Pod的前面(反过来又与NATS消息队列进行对话,侦听器从中检索消息并将其保存到Azure SQL数据库)。 All pods have resource request and limits set and everything is in a dedicated namespace. 所有Pod都设置了资源请求和限制,所有内容都位于专用的命名空间中。

I'm using a PowerShell script to cause the web application to generate a message for the NATS queue every 50 milliseconds. 我正在使用PowerShell脚本使Web应用程序每50毫秒为NATS队列生成一条消息。 I can see from a couple of ways that the Loadbalancer is only sending traffic to one pod: firstly the CPU graphs in the k8s dashboard show no activity for two of the pods and secondly I'm tracing the Environment. 我可以通过两种方式看到,Loadbalancer仅向一个Pod发送流量:首先,k8s仪表板中的CPU图形显示两个Pod没有任何活动,其次,我正在跟踪环境。 MachineName from the web app right the way through to a field in the database and I can see that it's only ever one MachineName. Web应用程序中的MachineName一直指向数据库中的一个字段,我可以看到它只是一个MachineName。 If I delete the pod that is receiving traffic a new pod immediately stars receiving traffic but it's still only that one pod out of three. 如果我删除接收流量的广告连播,则新的广告连播会立即显示接收流量,但仍然只有三分之一。

My understanding is that this isn't how the LoadBalancer is intended to work, ie the LoadBalancer should send traffic to all pods. 我的理解是,这不是LoadBalancer的工作方式,即LoadBalancer应该将流量发送到所有Pod。 Is that right and if so any clues as to what I'm doing wrong? 是正确的,如果有任何关于我做错事情的线索? My service file is as follows: 我的服务文件如下:

apiVersion: v1
kind: Service
metadata:
  name: megastore-web-service
spec:
  selector:
    app: megastore-web
  ports:
  - port: 80
  type: LoadBalancer

It sounds to me like your load balancer is working correctly. 在我看来,您的负载均衡器正在正常工作。 When traffic comes into a LB the LB will automatically direct traffic to the first available node. 当流量进入LB时,LB将自动将流量定向到第一个可用节点。 The fact that you can shutdown your POD and traffic is rerouted is what would be expected. 您可以关闭POD并重新路由流量这一事实是可以预期的。

This is a good article which helps explain how the LB works 这是一篇很好的文章,有助于解释LB的工作原理

https://blogs.msdn.microsoft.com/cie/2017/04/19/how-to-fix-load-balancer-not-working-in-round-robin-fashion-for-your-cloud-service/ https://blogs.msdn.microsoft.com/cie/2017/04/19/how-to-fix-load-balancer-not-working-in-round-robin-fashion-for-your-cloud-service/

To test this further, I would suggest you try opening a port on one of the PODs but not the others. 为了进一步测试,我建议您尝试打开其中一个POD上的端口,而不要打开其他POD。 Such as port 88 on POD2. 例如POD2上的端口88。 Then connect using the loadbalancer:88 and see if the connection gets routed to the correct POD. 然后使用负载均衡器进行连接:88,查看连接是否路由到正确的POD。

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

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