I create a infrastructure in Azure using following set of "az cli" commands
# Variables
location="eastus"
resourceGroup="nginx-lb-rg"
vnet="nginx-vnet"
subnet="nginx-subnet"
nsg="nginx-nsg"
publicIp="nginx-pubip"
lb="nginx-lb"
lbFrontend="nginx-frontend"
lbBackendPool="nginx-backend-pool"
lbProbe="nginx-health-probe"
lbRule="nginx-http-rule"
vmPrefix="nginx-vm"
adminUser="serveradmin"
adminPassword="5uper5ecureP@ssw0rd"
# Create resource group
az group create --name $resourceGroup --location $location
# Create virtual network and subnet
az network vnet create \
--resource-group $resourceGroup \
--name $vnet \
--address-prefixes "10.0.0.0/16" \
--subnet-name $subnet \
--subnet-prefix "10.0.1.0/24"
# Create NSG and allow SSH + HTTP
az network nsg create --resource-group $resourceGroup --name $nsg
az network nsg rule create --resource-group $resourceGroup --nsg-name $nsg \
--name allow-ssh --priority 100 \
--direction Inbound --access Allow --protocol Tcp \
--source-address-prefix '*' --destination-port-range 22
az network nsg rule create --resource-group $resourceGroup --nsg-name $nsg \
--name allow-http --priority 110 \
--direction Inbound --access Allow --protocol Tcp \
--source-address-prefix '*' --destination-port-range 80
# Create public IP
az network public-ip create \
--resource-group $resourceGroup \
--name $publicIp \
--sku Standard \
--allocation-method Static
# Create Load Balancer
az network lb create \
--resource-group $resourceGroup \
--name $lb \
--sku Standard \
--frontend-ip-name $lbFrontend \
--backend-pool-name $lbBackendPool \
--public-ip-address $publicIp \
--location $location
# Create health probe
az network lb probe create \
--resource-group $resourceGroup \
--lb-name $lb \
--name $lbProbe \
--protocol Http \
--port 80 \
--path /index.html
# Create load balancing rule
az network lb rule create \
--resource-group $resourceGroup \
--lb-name $lb \
--name $lbRule \
--protocol Tcp \
--frontend-port 80 \
--backend-port 80 \
--frontend-ip-name $lbFrontend \
--backend-pool-name $lbBackendPool \
--probe-name $lbProbe \
--disable-outbound-snAT true
# Create NICs, associate subnet, NSG, and backend pool
for i in 1 2; do
nic="${vmPrefix}-nic$i"
az network nic create \
--resource-group $resourceGroup \
--name $nic \
--vnet-name $vnet \
--subnet $subnet \
--network-security-group $nsg
az network nic ip-config address-pool add \
--resource-group $resourceGroup \
--lb-name $lb \
--address-pool $lbBackendPool \
--nic-name $nic \
--ip-config-name ipconfig1
done
# Create Ubuntu VMs with NGINX
for i in 1 2; do
az vm create \
--resource-group $resourceGroup \
--name "${vmPrefix}$i" \
--image "/subscriptions/8b8fdec4-790a-4019-a7e5-a8b5cb5a3d41/resourceGroups/Azuredevops/providers/Microsoft.Compute/images/PackerImage" \
--admin-username $adminUser \
--admin-password $adminPassword \
--nics "${vmPrefix}-nic$i" \
--location $location
done
The Ubuntu image used for VM's is a custom Ubuntu image. All resources got created without any issues. However when I test the URL "http://lb-public-ip/index.html", the URL times out. I connected to each of VM via Bastion and did "curl http://vm-private-ip/index.html" again each VM, that works, so VM's or the image or the local firewalls can be ruled out.
I also checked the NSG rules, the http is allowed and there is no rule denying anything. I also check the HealthProbes, they indicate the backend pool is 100% healthy.
Not sure what am I missing - any hints? - Thanks!