How to expose multiple kubernetes services trough single azure load balancer?

1/17/2018

I want to expose multiple services trough single load balancer. Each service points to exactly one pod.

So far I tried to:

kubectl expose <podName> --port=7000 

And in Azure portal to manually set either load balancing rules or Inbound Nat rules, pointing to exposed pod. So far I can connect to pod using external IP and specified port.

-- Łukasz Baran
azure
azure-kubernetes
azure-load-balancer
kubernetes

3 Answers

1/18/2018

Thanks guys. I think I have found viable solution to my problem. I should have been more specific about what I'm going to do.

I want to host game server over UDP. So any kubernetes ingress controller is not really an option, since they rarely support UDP routing. I also don't need to host multitude of services on single machine 1-4 of pods per single node is probably the maximum.

I have found about using :

hostNetwork: true 

in yaml config and it actually works pretty well for this scenario. I get IP directly from host node. I can then select matching node within load balancer and create NAT or load balancing rule

-- Łukasz Baran
Source: StackOverflow

1/18/2018

In Azure container service, Azure will use Load Balancer to expose k8s services, like this:

root@k8s-master-E27AE453-0:~# kubectl get svc
NAME         CLUSTER-IP    EXTERNAL-IP     PORT(S)          AGE
jasonnginx   10.0.41.194   52.226.33.200   8080:32011/TCP   4m
kubernetes   10.0.0.1      <none>          443/TCP          11m
mynginx      10.0.144.49   40.71.230.60    80:32366/TCP     5m
yournginx    10.0.147.28   40.71.226.23    80:32289/TCP     4m
root@k8s-master-E27AE453-0:~# 

Via Azure portal, check Azure load balancer frontend IP configuration(different IP address):

enter image description here

ACS will create Load Balancer rules and add rontend IP address automatically.

How to expose multiple kubernetes services trough single azure load balancer?

ACS expose k8s services through that Azure Load Balancer, do you mean you want to expose k8s services with a single Public IP address?

If you want to expose k8s services with a single public IP address, as Radek said, maybe you should use Nginx Ingress Controller.

The Ingress Controller works like this:

enter image description here

-- Jason Ye
Source: StackOverflow

1/17/2018

Depends on how you want to separate services on the same IP. The two ways that come to my mind are :

  • use NodePort services and then map some ports from your LB to that part on your cluster nodes. This gives separation by port.
  • way more interesting in my opinion is to use Ingress/IngressController. You would expose only IC on standard ports like 80 & 443 and then it will map to your services by hostname and uri
-- Radek 'Goblin' Pieczonka
Source: StackOverflow