Kubernetes - load balance multiple services using a single load balancer

12/6/2020

Is it possible to load balance multiple services using a single aws load balancer? If that's not possible I guess I could just use a nodejs proxy to forward from httpd pod to tomcat pod and hope it doesn't lag...

Either way which Loadbalancer is recommended for multiport services? CLB doesn't support mutliports and ALB doesn't support mutliport for a single / path. So I guess NLB is the right thing implement?

I'm trying to cut cost and move to k8s but I need to know if I'm choosing the right service. Tomcat and Httpd are both part of a single prod website but can't do path based routing.

Httpd pod service:

apiVersion: v1
kind: Service
metadata:
  name: httpd-service
  labels:
    app: httpd-service
  namespace: test1-web-dev
spec:
  selector:
    app: httpd
  ports:
    - name: port_80
      protocol: TCP
      port: 80
      targetPort: 80
    - name: port_443
      protocol: TCP
      port: 443
      targetPort: 443
    - name: port_1860
      protocol: TCP
      port: 1860
      targetPort: 1860

Tomcat pod service:

apiVersion: v1
kind: Service
metadata:
  name: tomcat-service
  labels:
    app: tomcat-service
  namespace: test1-web-dev
spec:
  selector:
    app: tomcat
  ports:
    - name: port_8080
      protocol: TCP
      port: 8080
      targetPort: 8080
    - name: port_1234
      protocol: TCP
      port: 1234
      targetPort: 1234
    - name: port_8222
      protocol: TCP
      port: 8222
      targetPort: 8222
-- John Doe
amazon-elb
amazon-web-services
kubernetes

2 Answers

12/6/2020

It's done like this: install Ingress controller (e.g. ingress-nginx) to your cluster, it's gonna be your loadbalancer looking into outside world.

Then configure Ingress resource(s) to drive traffic to services (as many as you want). Then you have a single Ingress controller (which means a single Loadbalancer) per cluster.

https://kubernetes.io/docs/concepts/services-networking/ingress/

-- Egor Stambakio
Source: StackOverflow

12/6/2020

You can do this, using Ingress controller backing with a load balancer, and use one path / you may make the Ingress tells the backing load balancer to route requests based on the Host header.

-- Asri Badlah
Source: StackOverflow