Home > database >  About the traffic flow with 'service' type 'LoadBalancer'
About the traffic flow with 'service' type 'LoadBalancer'

Time:06-08

I have one question which I couldn't find a clear explaination.

If I have a service :

apiVersion: v1
kind: Service
metadata:
  name: my-app-svc
  namespace: myns
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 8080
      targetPort: 8282
  selector:
    app: my-app

As you can see above, I explicitly declared type: LoadBalancer. I understand what it means. I am using AWS EKS. I wonder from traffic perspective, does it mean the incoming http traffic flow is :

Load Balancer --> Node port --> service port(8080) --> Pod port(8282)

Or:

Load Balancer --> service port(8080) --> Pod port(8282)

Which one is correct? If neither is correct, what would be the traffic flow in terms of the order in which each k8s component is involved?

CodePudding user response:

Load Balancer --> Node port --> service port(8080) --> Pod port(8282)

Your diagram is correct for instance mode:

Traffic reaching the ALB is routed to NodePort for your service and then proxied to your pods. This is the default traffic mode.

There is an option of using IP mode where you have AWS LB Controller installed and set alb.ingress.kubernetes.io/target-type: ip:

Traffic reaching the ALB is directly routed to pods for your service.

More details can be found here.

CodePudding user response:

When creating a Service, you have the option of automatically creating a cloud load balancer. This provides an externally-accessible IP address that sends traffic to the correct port on your cluster nodes.

By default, spec.allocateLoadBalancerNodePorts is true and type LoadBalancer Services will continue to allocate node ports in the cluster so the loadblancer routes the trqaffic to the nodes on nodeport.

You can optionally disable node port allocation for a Service of type=LoadBalancer, by setting the field spec.allocateLoadBalancerNodePorts to false. This should only be used for load balancer implementations that route traffic directly to pods as opposed to using node ports.

If spec.allocateLoadBalancerNodePorts is set to false on an existing Service with allocated node ports, those node ports will not be de-allocated automatically. You must explicitly remove the nodePorts entry in every Service port to de-allocate those node ports

  • Related