Steps Overview - Azure - VPC
Steps Overview - Azure - VPC
services are completely free, especially at the scale described in the above design. Here's a
breakdown of the resources used and what might be free under the Azure Student plan:
Virtual Machines: Since you’re creating multiple VMs (Web, App, DB), only one small
VM is free for 750 hours/month. The others will consume your $100 credit, depending on
size and duration of use.
Load Balancer: A load balancer is not free and will use part of your credit.
Public IP and NAT Gateway: Both services will incur charges.
Storage: VM storage beyond the free limit of 5 GB of blob storage will also consume
credit.
Steps Overview:
bash
Copy code
az network public-ip create \
--resource-group MyResourceGroup \
--name MyLoadBalancerPublicIP \
--allocation-method Static \
--sku Standard
bash
Copy code
az network lb create \
--resource-group MyResourceGroup \
--name MyLoadBalancer \
--frontend-ip-name MyFrontendIP \
--public-ip-address MyLoadBalancerPublicIP \
--backend-pool-name MyBackendPool
bash
Copy code
az network lb probe create \
--resource-group MyResourceGroup \
--lb-name MyLoadBalancer \
--name MyHealthProbe \
--protocol Tcp \
--port 80
bash
Copy code
az network lb rule create \
--resource-group MyResourceGroup \
--lb-name MyLoadBalancer \
--name MyHTTPRule \
--protocol Tcp \
--frontend-port 80 \
--backend-port 80 \
--frontend-ip-name MyFrontendIP \
--backend-pool-name MyBackendPool \
--probe-name MyHealthProbe \
--idle-timeout 4 \
--enable-tcp-reset true
4. Create VMs in the Web Subnet and Associate with the Load Balancer
You will create two VMs (for load balancing) and place them in the Web subnet.
bash
Copy code
# Create VM 1 in Web Subnet
az vm create \
--resource-group MyResourceGroup \
--name WebVM1 \
--vnet-name MyVnet \
--subnet WebSubnet \
--image Ubuntu2204 \
--admin-username azureuser \
--admin-password Niraj98452#### \
--authentication-type password \
--enable-secure-boot true \
--enable-vtpm true \
--nsg WebNSG \
--no-wait
bash
Copy code
# Add WebVM1 to Load Balancer Backend Pool
az network nic ip-config address-pool add \
--address-pool MyBackendPool \
--ip-config-name ipconfig1 \
--nic-name WebVM1VMNic \
--resource-group MyResourceGroup \
--lb-name MyLoadBalancer
bash
Copy code
az network public-ip create \
--resource-group MyResourceGroup \
--name NatGatewayPublicIP \
--sku Standard \
--allocation-method Static
bash
Copy code
az network nat gateway create \
--resource-group MyResourceGroup \
--name MyNatGateway \
--public-ip-addresses NatGatewayPublicIP
Step 3: Associate the NAT Gateway with the Private Subnets (App and Db Subnets)
bash
Copy code
# Associate NAT Gateway with Application Subnet
az network vnet subnet update \
--resource-group MyResourceGroup \
--vnet-name MyVnet \
--name AppSubnet \
--nat-gateway MyNatGateway
bash
Copy code
# Create NSG for Web Subnet
az network nsg create \
--resource-group MyResourceGroup \
--name WebNSG
bash
Copy code
# Allow HTTP/HTTPS inbound to Web servers
az network nsg rule create \
--resource-group MyResourceGroup \
--nsg-name WebNSG \
--name AllowHTTP \
--priority 100 \
--protocol Tcp \
--direction Inbound \
--destination-port-ranges 80 443 \
--access Allow
bash
Copy code
# Allow traffic from Web Subnet (10.0.1.0/24)
az network nsg rule create \
--resource-group MyResourceGroup \
--nsg-name AppNSG \
--name AllowWebToApp \
--priority 100 \
--protocol Tcp \
--direction Inbound \
--source-address-prefixes 10.0.1.0/24 \
--destination-port-ranges 8080 \
--access Allow
bash
Copy code
# Allow traffic from App Subnet (10.0.2.0/24)
az network nsg rule create \
--resource-group MyResourceGroup \
--nsg-name DbNSG \
--name AllowAppToDb \
--priority 100 \
--protocol Tcp \
--direction Inbound \
--source-address-prefixes 10.0.2.0/24 \
--destination-port-ranges 3306 \
--access Allow
bash
Copy code
# Associate WebNSG with Web Subnet
az network vnet subnet update \
--resource-group MyResourceGroup \
--vnet-name MyVnet \
--name WebSubnet \
--network-security-group WebNSG