Azure Load Balancer to balance the load between multiple ports but in same VM (Backend Pool) - azure

I have having a hard time find a solution for this.
I have an Azure Internal Load Balancer (level 4). And I have ONLY one Virtual Machine act as the backend pool for the said Load Balancer.
And fun part starts here, I have multiple Docker containers running on that Virtual Machine. Running Nginx Web servers on ports 8080 and 8081.
And now I want to balance the load between these two ports. Literally what I want is something like below in the photo:
So according to the photo, the request comes from abc.xyz.com and it should hit the Load Balancer, and then it should route the traffic to the only VM running multiple docker containers in multiple ports.
How can I achieve this behavior?
I have already setup A frontend configuration with private ip, a rule, backend pool

As per this article(https://learn.microsoft.com/en-us/azure/container-instances/container-instances-virtual-network-concepts#unsupported-networking-scenarios), placing an Azure Load Balancer in front of container instances in a networked container group is not supported and similarly it is not possible to route the traffic on containers to their specific ports running on a single Virtual Machine. The above solution works on VM level not on container level.
The only workaround for this scenario would be to use Azure Application gateway as Microservice architecture is supported on App gateway. To probe on different ports, you need to configure multiple HTTP settings. Reference:
https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-faq#can-one-backend-pool-serve-many-applications-on-different-ports
Azure Application Gateway is a web traffic load balancer that enables you to manage traffic to your web applications. And you can create an internal application gateway. To do that you can create an Application Gateway with both public and private frontend IP address and do not create any listeners for the public frontend IP address. Application Gateway will not listen to any traffic on the public IP address if no listeners are created for it.
Reference: https://learn.microsoft.com/en-us/azure/application-gateway/configuration-front-end-ip ,
https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-faq#how-do-i-use-application-gateway-v2-with-only-private-frontend-ip-address

Related

Cannot SSH into scale set instances using application gateway

I've created a scale-set with two instances and connected the scale-set with application gateway. Now, I want to ssh into the instances but I cannot do it using application gateway. The instances do not have public IP assigned.
I was able to ssh into instances using load-balancer(when scale-set was connected to load balancer).
I tried to create an NSG and associate NSG with application gateway subnet, but still cannot ssh into scale set instances.
How can I ssh into scale set instances that is behind application gateway?
I dont think you can do that, Application Gateway operates on layer 7 (so HTTP), so you are pretty much limited to HTTP traffic only using Application gateway.
You can attach Load Balancer to your scale set and use that only for natting your ssh connections and bypass load balancer for application gateway connections
other options: vpn\jumpbox
Application gateway will be connecting to backend VMs using a different port. I faced this issue, but I was using load balancer. Load balancer was using port 50,000 to connect to my backend instance. I was not able to SSH through port 22 but was able to SSH using port 50,000. You can check which port is application gateway using to connect to backend instance and use that port to SSH. I believe it should work.

Azure gateway with a virtual network

I've got multiple questions on the setup of a gateway and VM, so here is what I have actually.
I've got an Application Gateway, and two VM Ubuntu, everything hosted on Azure. They are all on the same Virtual Network. Both VM have only a private IP (10.1.0.4 and 10.1.0.5) and the Gateway have a private IP (10.1.1.4) and a public IP. Because only the Gateway have a public IP, I guess that everything have to go through it, and this is what I want to.
The goals I try to achieve :
Make a load balancer on the port 1680, redirected to port 1680.
To redirect the SSH of each VM to connect specifically to one because at the moment, they have no public IP. Is it possible to do this with a path based rule ? Like www.example.com/VM1 to connect by SSH to the first VM ? If no, what can be used to differentiate the SSH connection of the VM1 and of the VM2 ?
To redirect the port 80 of the gateway to the port 8080 of a specific VM. As my previous example, www.example.com/adminPanelVM1 to connect to the first VM on port 80 (redirected to port 8080 on the VM)
I already managed to create the redirection of the port 1680 of the Gateway with an HTTP Parameter, a Listener and a Rule.
Azure Application Gateway
The Azure Application Gateway operates at the layer 7 in the OSI model on the HTTP/HTTPS/WebSocket protocols, because of that any other protocol (like SSH), is not possible to route.
You got a few options tho.
You can use a Network Security Group, or NSG, for access control to your virtual machines. In the NSG you define where the traffic can come from that is allowed access to the VMs.
A NSG behaves like a access-control-list filtering traffic based on source and destination information and evaluating rules in order of priority. See this page for more information about NSGs.
Another option is to use a load balancer.
Azure Load Balancer
If you need to do port mapping, like you describe in your question, then a simple load balancer might be a better solution for you. An Azure Load Balancer works at a lower level in the in the OSI model, namely layer 4 (transport layer), handling TCP/UDP traffic.
So, if you are using a load balancer, then you can set up NAT rules to forward your traffic to specific machines, in other words, if you want to do:
LB port 1234 redirects to VM1 port 22 and
LB port 4312 redirects to VM2 port 22
you can do that using PowerShell as described in the Creating a public load balancer in Resource Manager by using PowerShell article.
There are quite a few steps but it walks you through the whole process of creating NAT rules, NICs and associated virtual machines.
Azure Application Gateway vs Azure Load Balancer?
These two cervices are distinctly different services and are trying to solve different problem, although those problems might look similar :)
The primary uses of an Application Gateway are:
SSL termination
cookie-based session affinity
round robin for load balancing traffic
Where as the Azure Load Balancer service works as the TCP/UDP level and support e.g. port mapping.
Cost wise, the load balancer service is free while the application gateway is billed per hour.
There are many great articles on this topic, when to pick which service. See for example the links for more details
When to use Azure Load Balancer or Application Gateway
Frequently asked questions for Application Gateway

Access Azure Service Fabric application from internet

I think I'm missing something that is on surface.
I have created SF cluster in Azure. It has a Load Balancer and a network with 3 VMs (nodes) which have IP addresses in 10.0.0.0/16.
When I'm asking Load balancer for application endpoint it responds with node IP address. (I captured packets with WireShark) But I can't access it because the network is private.
A bit more info about my case: 3xA0 instances, net.tcp:20001 endpoints, firewall allow connections, ports opened and listening, i have public IP address assigned to balancer, probe for service port.
On your load balancer you will need to assign a public IP address. You can find some really good detailed guides in the documentation for this.
Ok Here is it:
When you want to communicate to the service from outside the cluster - just use load balancer IP and you don't need the naming server communication. Load balancer has probs that can check ports on each node in cluster and forward your request to random instance which has service you are asking.
When you want to communicate one microservice to another within the cluster then you have 2 options:
ask naming service through load balancer and then communicate to the service directly.
if you know for sure that the service should be on every node in your cluster - you can just communicate to localhost directly.
When you want to communicate from separate vm to the microservice in the cluster from within cluster's virtual network (you can connect WebApp to the cluster using vpn) then you can ask naming service through load balancer but using Service fabric HTTP API because you will not be able to use service fabric classes on VM wich doesn't have Service Fabric SDK installed. Here is an example of service resolving: https://github.com/lAnubisl/ServiceFabricHttpApiClient

Azure secured connection for Load balancer?

we are creating a virtual machines in resource manager portal with internet facing load balancer. In virtual machines we have more than 10 web application running in different ports. we have port mapping in load balancer to access application as public. Now our requirement is how can we make secured connection for all applications? can we make "https" for load balancer public IP?
please let me know if any possibilities to make secure connection for loadbalancer.
Thanks,
Selva
you can go with Azure application gateway to do the external SSL termination.Then setup an internal loadbalancer to do the routing.
https://azure.microsoft.com/en-in/documentation/articles/application-gateway-ssl-arm/
https://azure.microsoft.com/en-in/documentation/articles/application-gateway-ilb/

Azure multiple VM with same Virtual Public IP and Host name mapped to Virtual Public IP

I am running following two VM's on Azure within same cloud service.
HOST NAME
First
PUBLIC VIRTUAL IP (VIP) ADDRESS
104.xx.xx.26
HOST NAME
Second
PUBLIC VIRTUAL IP (VIP) ADDRESS
104.xx.xx.26
On First nginx is running on port 80 and on Second no service is running on port 80
Now the question is :
I have mapped # host name to above public IP(104.xx.xx.26).
How would azure decide the VM the request to route to?
Will azure route the request to Second VM where no service is running on port 80?
Update :
This Question is not related to load balancing!
I just want all my http requests to be directed to First VM and that's the way its working now.
My concern is how azure is routing the request. Can it route the request to second server some time, In that case response won't be serverd as no nginx is not running on Second Server.
I will using second server for diffrent Services.
E.g.
First Server will have Php,Nginx installed
Second Server will have Mysql Installed
I want all the request on port 80 to be directed to first server.
In order to route traffic between the two VMs of the same availability set you will have to setup a load-balanced set of endpoints, you can find all the gory details of how to do it
Click here https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-load-balance/
Availability sets are not responsible for load balancing as they ensure at least one VM within the set remains available.
There are a few different approaches to distribute load in Azure. For public facing services running on VMs within the same Cloud Service, the perhaps most accessible way is to configure a load-balanced set for the service. In your case, a load-balanced set for port 80 for both VMs. Azure will then distribute the traffic across both VMs using round-robin provided they run services on port 80.

Resources