AKS LoadBalancer only sends traffic to one pod

时间:2019-01-09 22:05:58

标签: azure kubernetes azure-kubernetes

I have a service configured as a LoadBalancer running on a five-node cluster running 1.9.11. 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). All pods have resource request and limits set and everything is in a dedicated namespace.

I’m using a PowerShell script to cause the web application to generate a message for the NATS queue every 50 milliseconds. 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. 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. 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. 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

1 个答案:

答案 0 :(得分:2)

在我看来,您的负载均衡器正在正常工作。当流量进入LB时,LB将自动将流量定向到第一个可用节点。您可以关闭POD并重新路由流量这一事实是可以预期的。

这是一篇很好的文章,有助于解释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/

为进一步测试,我建议您尝试打开其中一个POD上的端口,而不是其他POD。例如POD2上的端口88。然后使用负载均衡器进行连接:88,查看连接是否路由到正确的POD。