Kubernetes on Azure: assign different external IP to different services

7/26/2017

I create a sample setup of Kubernets cluster on Azure using Azure Container Service, and it did its job just fine. I set up several containers and services within the Kubernetes, no problem with that.

What makes me fuzzy is that if, say, I run several nginx containers and want to expose it via different external IPs, I can't do that for what I know and understand.

Azure approach is that I can set up Service and set type: LoadBalancer and as I create it Azure will "connect" LoadBalancer attached to client nodes to my service.

But this way I can only attach one external IP to all of my services which is not something I need. In my example when I run several nginx containers I'd like to expose its 80/tcp ports on different IPs so I can these IPs in DNS, not on different ports of the single IP.

How can I overcome that? Please help!

-- Alexander
azure
external
kubernetes

2 Answers

7/27/2017

In Azure container service, to expose a kubernetes service to Internet, we should use Azure Load balancer. As Radek said, several containers in one pod, and use the same load balancer to keep HA.

If you want to expose several containers to Internet with different Public IP addresses, we can create several pods, and expose them to Internet, in this way, containers with different public IP addresses.

The relationship about pod, containers and node, like this: enter image description here

We create several containers in one pod, several pods in one node(host), several pods work for one service. A service works as a cluster, one service with one public IP address.

So, if you want to create several nginx containers with different public IP addresses, we can create several services to archive this:

Create one or two nginx containers in one service, and expose several services to Internet.

root@k8s-master-7273A780-0:~# kubectl run jasonnginx --replicas=1 --image nginx
root@k8s-master-7273A780-0:~# kuberctl run mynginx --replicas=2 --image nginx
root@k8s-master-7273A780-0:~# kubectl expose deployments mynginx --port=80 --type=LoadBalancer
root@k8s-master-7273A780-0:~# kubectl expose deployments jasonnginx --port=80 --type=LoadBalancer
root@k8s-master-7273A780-0:~# kubectl get svc
NAME         CLUSTER-IP     EXTERNAL-IP     PORT(S)        AGE
jasonnginx   10.0.114.116   52.168.176.18   80:30153/TCP   5m
kubernetes   10.0.0.1       <none>          443/TCP        15m
mynginx      10.0.205.127   13.82.102.171   80:31906/TCP   6m
root@k8s-master-7273A780-0:~# kubectl get pods
NAME                          READY     STATUS    RESTARTS   AGE
jasonnginx-1417538491-v79mw   1/1       Running   0          20m
mynginx-1396894033-78njj      1/1       Running   0          21m
mynginx-1396894033-pmhjh      1/1       Running   0          21m

We can find the Load balancer frontend IP settings(two public IP addresses) via Azure portal: enter image description here

-- Jason Ye
Source: StackOverflow

7/26/2017

Looking at your linked Azure docs, it does not seem like it really differs from it should do on any cloud. I think you miss understood how it is supposed to be used.

When you create a service of any type, it is intended to provide service that does not differ. If it's pointing to multiple endpoints, it does that to LoadBalance traffic and provide HA. There is zero reason for this to be exposed externally on an IP per endpoint basis.

But, if you need to expose different services on different IPs, you just create both services as LoadBalancer service type, and every svc should receive its unique external load balancer (thus IP).

The behaviour you described (one loadbalancer, multiple services exposed externally) sounds much closer to what you can accomplish with Ingress/IngressController.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow