3

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
  • 1,229
  • 3
  • 24
  • 47

4 Answers4

3

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
  • 21,554
  • 7
  • 52
  • 48
3

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
  • 13,710
  • 2
  • 16
  • 25
0

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
  • 1,229
  • 3
  • 24
  • 47
  • can you expand on this solution, such as posting the full yaml to configure the service? – Choco Feb 08 '21 at 05:21
0

Create multiple nodePort type service, and fix the nodePort. And the cloud load balancer, set multiple listener groups. The listen port is same as the service's nodeport, and the target are all the worker nodes.

yixing yan
  • 173
  • 1
  • 7