├── README.md ├── v1 ├── AppGateway │ ├── jumpbox.sh │ ├── lab-infra.ps1 │ ├── sample.html │ └── sources.list ├── Azure Bastion │ └── lab-infra.ps1 ├── Azure Load Balancer │ ├── jumpbox.sh │ ├── lab-infra.ps1 │ └── sample.html ├── GatewayTransit │ ├── configureSpoke1.sh │ ├── configureSpoke2.sh │ └── lab-infra.ps1 ├── Peering │ └── lab-infra.ps1 └── VNet-to-VNet │ └── lab-infra.ps1 └── v2 ├── 050- Administer Virtual Networking └── nsg-prep-infra.ps1 ├── 060-Administer Intersite Connectivity ├── peering-pref-infra.ps1 └── service-endpoints-prep-infra.ps1 ├── 070-Administer Network Traffic ├── appgw-prep-infra.ps1 └── loadbalancer-prep-infra.ps1 ├── 090-Administer Azure Virtual Machines └── bastion-prep-infra.ps1 └── 120-Administer Monitoring └── monitoring-prep-infra.ps1 /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Azure AZ-104 Exam Preparation Scripts 4 | 5 | **NOTE: This repository has been updated to v2, which includes refreshed scripts written in PowerShell 7 and aligned with the new course topics. The v1 directory is for reference purposes only.** 6 | 7 | ## About the AZ-104 Exam 8 | The Azure AZ-104 exam, known as the Microsoft Azure Administrator Associate certification, assesses candidates' abilities to manage Azure identities and governance, implement and manage storage, deploy and manage Azure compute resources, configure and manage virtual networking, and monitor and back up Azure resources. This repository hosts scripts and resources aimed at aiding individuals in preparing for the AZ-104 exam, with practical use cases and exercises across various administrative domains. 9 | 10 | ## Folder Structure and Topics 11 | 12 | The repository is organized into two main versions: 13 | 14 | - `v1`: Contains the original scripts and resources based on the previous exam topics. 15 | - `v2`: This is the latest version with updated scripts and resources that reflect the most recent exam topics and are written using PowerShell 7. 16 | 17 | Within `v2`, you will find folders such as: 18 | 19 | - `050-Administer Virtual Networking`: Scripts for managing and configuring Azure virtual networks, including network connectivity and integration with on-premises networks. 20 | - `060-Administer Intersite Connectivity`: Tools and configurations for managing intersite connectivity features like VPN Gateway and Azure ExpressRoute. 21 | - `070-Administer Network Traffic`: Best practices and scripts for routing and controlling network traffic within Azure, including Network Watcher and traffic analytics. 22 | - `090-Administer Azure Virtual Machines`: Measures for managing and configuring Azure virtual machines, including VM deployment, scaling, and management. 23 | - `120-Administer Monitoring`: Operational scripts for monitoring Azure resources, setting up alerts, and log analytics. 24 | 25 | ## Prerequisites 26 | 27 | Before running the scripts, ensure you have the following prerequisites installed and configured: 28 | 29 | - .NET Framework 30 | - PowerShell 7 31 | - Azure PowerShell Module 32 | - Azure Command-Line Interface (CLI) 33 | 34 | ## Issues and Contributions 35 | 36 | Encounter an issue or error in the code? Please feel free to open an issue in this repository. Contributions are also welcome if you have enhancements or fixes for the scripts provided. 37 | 38 | ## License 39 | 40 | For learning and development purposes only. 41 | -------------------------------------------------------------------------------- /v1/AppGateway/jumpbox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install sshpass -y 4 | for i in {0..1} 5 | do 6 | j=$(($i + 4)) 7 | k=$(($i + 1)) 8 | greenIp="10.0.1.$j" 9 | sshpass -p "VMP@55w0rd" \ 10 | ssh -o StrictHostKeyChecking=no kodekloud@$greenIp bash -c \ 11 | "'export VAR=$i 12 | printenv | grep VAR 13 | echo "Setting up green VM" 14 | sudo apt install apache2 -y 15 | sudo chmod -R -v 777 /var/www/ 16 | sudo curl "https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/AppGateway/sample.html" > /var/www/html/index.html 17 | sed -i "s/PAGECOLOR/green/g" /var/www/html/index.html 18 | sed -i "s/VMID/$k/g" /var/www/html/index.html 19 | exit 20 | '" 21 | done 22 | 23 | for i in {0..1} 24 | do 25 | j=$(($i + 4)) 26 | k=$(($i + 1)) 27 | redIp="10.0.2.$j" 28 | sshpass -p "VMP@55w0rd" \ 29 | ssh -o StrictHostKeyChecking=no kodekloud@$redIp bash -c \ 30 | "'export VAR=$i 31 | printenv | grep VAR 32 | echo "Setting up red VM" 33 | sudo apt install apache2 -y 34 | sudo chmod -R -v 777 /var/www/ 35 | sudo mkdir -v /var/www/html/red/ 36 | sudo curl "https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/AppGateway/sample.html" > /var/www/html/index.html 37 | sed -i "s/PAGECOLOR/red/g" /var/www/html/index.html 38 | sed -i "s/VMID/$k/g" /var/www/html/index.html 39 | cat /var/www/html/index.html > /var/www/html/red/red.html 40 | exit 41 | '" 42 | 43 | done 44 | 45 | for i in {0..1} 46 | do 47 | j=$(($i + 4)) 48 | k=$(($i + 1)) 49 | blueIp="10.0.3.$j" 50 | sshpass -p "VMP@55w0rd" \ 51 | ssh -o StrictHostKeyChecking=no kodekloud@$blueIp bash -c \ 52 | "'export VAR=$i 53 | printenv | grep VAR 54 | echo "Setting up blue VM" 55 | sudo apt install apache2 -y 56 | sudo chmod -R -v 777 /var/www/ 57 | sudo mkdir -v /var/www/html/blue/ 58 | sudo curl "https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/AppGateway/sample.html" > /var/www/html/index.html 59 | sed -i "s/PAGECOLOR/blue/g" /var/www/html/index.html 60 | sed -i "s/VMID/$k/g" /var/www/html/index.html 61 | cat /var/www/html/index.html > /var/www/html/blue/blue.html 62 | exit 63 | '" 64 | done 65 | -------------------------------------------------------------------------------- /v1/AppGateway/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | #Application Gateway Demo Infra - v2.0, written by Rithin Skaria 2 | Clear-Host 3 | #Variables 4 | $rg = read-host "(new) Resource Group Name" 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | $VMSize = "Standard_B1s" 9 | 10 | #Creating VM credential; use your own password and username by changing the variables if needed 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | 13 | Write-Host "Application Gateway Demo Infra - v2.0, written by Rithin Skaria" ` 14 | -ForegroundColor "Red" -BackgroundColor "White" 15 | 16 | #Create RG 17 | New-AzResourceGroup -n $rg -l $region 18 | 19 | #########-----Create resources---------###### 20 | 21 | #Creating vnet 22 | 23 | Write-Host "Adding subnet configuration" ` 24 | -ForegroundColor "Yellow" -BackgroundColor "Black" 25 | 26 | $jumpBox = New-AzVirtualNetworkSubnetConfig ` 27 | -Name 'jumpboxSubnet' ` 28 | -AddressPrefix 10.0.0.0/24 29 | 30 | $greenSubnet = New-AzVirtualNetworkSubnetConfig ` 31 | -Name 'greenSubnet' ` 32 | -AddressPrefix 10.0.1.0/24 33 | 34 | $redSubnet = New-AzVirtualNetworkSubnetConfig ` 35 | -Name 'redSubnet' ` 36 | -AddressPrefix 10.0.2.0/24 37 | 38 | $blueSubnet = New-AzVirtualNetworkSubnetConfig ` 39 | -Name 'blueSubnet' ` 40 | -AddressPrefix 10.0.3.0/24 41 | 42 | Write-Host "Creating color-web-vnet" ` 43 | -ForegroundColor "Yellow" -BackgroundColor "Black" 44 | 45 | $vnet = New-AzVirtualNetwork ` 46 | -ResourceGroupName $rg ` 47 | -Location $region ` 48 | -Name "color-web-vnet" ` 49 | -AddressPrefix 10.0.0.0/16 ` 50 | -Subnet $jumpBox, $greenSubnet, $redSubnet, $blueSubnet 51 | 52 | #---------------------------------------------------# 53 | 54 | #-------------------NSG--------------------------------# 55 | 56 | $webRule = New-AzNetworkSecurityRuleConfig -Name web-rule -Description "Allow HTTP" -Access Allow ` 57 | -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * ` 58 | -DestinationAddressPrefix * -DestinationPortRange 80 59 | 60 | $networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName $rg ` 61 | -Location $region -Name "appGwNSG" -SecurityRules $rdpRule 62 | 63 | Set-AzVirtualNetworkSubnetConfig -Name greenSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.1.0/24" ` 64 | -NetworkSecurityGroup $networkSecurityGroup 65 | 66 | Set-AzVirtualNetworkSubnetConfig -Name redSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.2.0/24" ` 67 | -NetworkSecurityGroup $networkSecurityGroup 68 | 69 | Set-AzVirtualNetworkSubnetConfig -Name blueSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.3.0/24" ` 70 | -NetworkSecurityGroup $networkSecurityGroup 71 | 72 | $vnet | Set-AzVirtualNetwork 73 | 74 | #---------------------------------------------------# 75 | 76 | #---------------------green Pool Servers------------------------------# 77 | 78 | for($i=1; $i -le 2; $i++){ 79 | 80 | $workloadNIC = New-AzNetworkInterface -Name "green-0$i-nic" -ResourceGroupName $rg ` 81 | -Location $region -SubnetId $vnet.Subnets[1].Id 82 | 83 | Write-Host "----------------------------------------------------" ` 84 | -ForegroundColor "Yellow" -BackgroundColor "Black" 85 | 86 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 87 | 88 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 89 | 90 | $VirtualMachine = New-AzVMConfig -VMName "green-0$i" -VMSize $VMSize 91 | 92 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 93 | 94 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 95 | -Linux -ComputerName "green0$i" -Credential $credential 96 | 97 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $workloadNIC.Id 98 | 99 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 100 | -PublisherName 'Canonical' ` 101 | -Offer '0001-com-ubuntu-server-jammy' ` 102 | -Skus '22_04-lts-gen2' ` 103 | -Version latest 104 | 105 | Write-Host "Creating VM green-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 106 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 107 | 108 | } 109 | 110 | #---------------------------------------------------# 111 | 112 | #---------------------red Pool Servers------------------------------# 113 | 114 | for($i=1; $i -le 2; $i++){ 115 | 116 | $workloadNIC = New-AzNetworkInterface -Name "red-0$i-nic" -ResourceGroupName $rg ` 117 | -Location $region -SubnetId $vnet.Subnets[2].Id 118 | 119 | Write-Host "----------------------------------------------------" ` 120 | -ForegroundColor "Yellow" -BackgroundColor "Black" 121 | 122 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 123 | 124 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 125 | 126 | $VirtualMachine = New-AzVMConfig -VMName "red-0$i" -VMSize $VMSize 127 | 128 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 129 | 130 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 131 | -Linux -ComputerName "red0$i" -Credential $credential 132 | 133 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $workloadNIC.Id 134 | 135 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 136 | -PublisherName 'Canonical' ` 137 | -Offer '0001-com-ubuntu-server-jammy' ` 138 | -Skus '22_04-lts-gen2' ` 139 | -Version latest 140 | 141 | Write-Host "Creating VM red-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 142 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 143 | 144 | } 145 | 146 | #---------------------------------------------------# 147 | 148 | #---------------------blue Pool Servers------------------------------# 149 | 150 | for($i=1; $i -le 2; $i++){ 151 | 152 | $workloadNIC = New-AzNetworkInterface -Name "blue-0$i-nic" -ResourceGroupName $rg ` 153 | -Location $region -SubnetId $vnet.Subnets[3].Id 154 | 155 | Write-Host "----------------------------------------------------" ` 156 | -ForegroundColor "Yellow" -BackgroundColor "Black" 157 | 158 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 159 | 160 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 161 | 162 | $VirtualMachine = New-AzVMConfig -VMName "blue-0$i" -VMSize $VMSize 163 | 164 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 165 | 166 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 167 | -Linux -ComputerName "blue0$i" -Credential $credential 168 | 169 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $workloadNIC.Id 170 | 171 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 172 | -PublisherName 'Canonical' ` 173 | -Offer '0001-com-ubuntu-server-jammy' ` 174 | -Skus '22_04-lts-gen2' ` 175 | -Version latest 176 | 177 | Write-Host "Creating VM blue-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 178 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 179 | 180 | } 181 | 182 | 183 | 184 | #---------------------------------------------------# 185 | 186 | #---------------------Jumpbox------------------------------# 187 | 188 | Write-Host "Creating jumpbox VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 189 | $jumpVm = New-AzVM -Name jumpbox-vm ` 190 | -ResourceGroupName $rg ` 191 | -Location $region ` 192 | -Size 'Standard_B1s' ` 193 | -Image Ubuntu2204 ` 194 | -VirtualNetworkName color-web-vnet ` 195 | -SubnetName jumpboxSubnet ` 196 | -PublicIpAddressName 'jumpbox-appgw-pip' ` 197 | -Credential $credential 198 | 199 | Write-Host "Running script on jumpbox..." -BackgroundColor Green -ForegroundColor White 200 | 201 | $Params = @{ 202 | ResourceGroupName = $rg 203 | VMName = 'jumpbox-vm' 204 | Name = 'CustomScript' 205 | Publisher = 'Microsoft.Azure.Extensions' 206 | ExtensionType = 'CustomScript' 207 | TypeHandlerVersion = '2.1' 208 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/AppGateway/jumpbox.sh'); commandToExecute = './jumpbox.sh'} 209 | } 210 | Set-AzVMExtension @Params 211 | 212 | #---------------------------------------------------# 213 | 214 | #---------------------Output------------------------------# 215 | 216 | Write-Host "Deployment Completed!!" -BackgroundColor Green -ForegroundColor White 217 | 218 | $fqdn = $jumpVm.FullyQualifiedDomainName 219 | Write-Host "Jumpbox VM DNS name : $fqdn " 220 | for ($i=1; $i -le 2; $i++){ 221 | 222 | $vmIP= (Get-AzNetworkInterface -Name "green-0$i-nic").IpConfigurations.PrivateIPAddress 223 | Write-Host "Private IP (green-0$i) :$vmIP" 224 | 225 | } 226 | for ($i=1; $i -le 2; $i++){ 227 | 228 | $vmIP= (Get-AzNetworkInterface -Name "red-0$i-nic").IpConfigurations.PrivateIPAddress 229 | Write-Host "Private IP (red-0$i) :$vmIP" 230 | 231 | } 232 | for ($i=1; $i -le 2; $i++){ 233 | 234 | $vmIP= (Get-AzNetworkInterface -Name "blue-0$i-nic").IpConfigurations.PrivateIPAddress 235 | Write-Host "Private IP (blue-0$i) :$vmIP" 236 | 237 | } 238 | -------------------------------------------------------------------------------- /v1/AppGateway/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hi from PAGECOLOR-VMID

4 | 5 | 6 | -------------------------------------------------------------------------------- /v1/AppGateway/sources.list: -------------------------------------------------------------------------------- 1 | ## Note, this file is written by cloud-init on first boot of an instance 2 | ## modifications made here will not survive a re-bundle. 3 | ## if you wish to make changes you can: 4 | ## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg 5 | ## or do the same in user-data 6 | ## b.) add sources in /etc/apt/sources.list.d 7 | ## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl 8 | 9 | # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 10 | # newer versions of the distribution. 11 | deb http://archive.ubuntu.com/ubuntu/ focal main restricted 12 | deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted 13 | 14 | ## Major bug fix updates produced after the final release of the 15 | ## distribution. 16 | deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted 17 | deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted 18 | 19 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 20 | ## team. Also, please note that software in universe WILL NOT receive any 21 | ## review or updates from the Ubuntu security team. 22 | deb http://archive.ubuntu.com/ubuntu/ focal universe 23 | deb-src http://archive.ubuntu.com/ubuntu/ focal universe 24 | deb http://archive.ubuntu.com/ubuntu/ focal-updates universe 25 | deb-src http://archive.ubuntu.com/ubuntu/ focal-updates universe 26 | 27 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 28 | ## team, and may not be under a free licence. Please satisfy yourself as to 29 | ## your rights to use the software. Also, please note that software in 30 | ## multiverse WILL NOT receive any review or updates from the Ubuntu 31 | ## security team. 32 | deb http://archive.ubuntu.com/ubuntu/ focal multiverse 33 | deb-src http://archive.ubuntu.com/ubuntu/ focal multiverse 34 | deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse 35 | deb-src http://archive.ubuntu.com/ubuntu/ focal-updates multiverse 36 | 37 | ## N.B. software from this repository may not have been tested as 38 | ## extensively as that contained in the main release, although it includes 39 | ## newer versions of some applications which may provide useful features. 40 | ## Also, please note that software in backports WILL NOT receive any review 41 | ## or updates from the Ubuntu security team. 42 | deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse 43 | deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse 44 | 45 | deb http://security.ubuntu.com/ubuntu focal-security main restricted 46 | deb-src http://security.ubuntu.com/ubuntu focal-security main restricted 47 | deb http://security.ubuntu.com/ubuntu focal-security universe 48 | deb-src http://security.ubuntu.com/ubuntu focal-security universe 49 | deb http://security.ubuntu.com/ubuntu focal-security multiverse 50 | deb-src http://security.ubuntu.com/ubuntu focal-security multiverse 51 | 52 | ## Uncomment the following two lines to add software from Canonical's 53 | ## 'partner' repository. 54 | ## This software is not part of Ubuntu, but is offered by Canonical and the 55 | ## respective vendors as a service to Ubuntu users. 56 | # deb http://archive.canonical.com/ubuntu wily partner 57 | # deb-src http://archive.canonical.com/ubuntu wily partner 58 | -------------------------------------------------------------------------------- /v1/Azure Bastion/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | 2 | Clear-Host 3 | #Variables 4 | $rg = read-host "(new) Resource Group Name" 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | 9 | #Creating VM credential; use your own password and username by changing the variables if needed 10 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 11 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 12 | 13 | #Create RG 14 | New-AzResourceGroup -n $rg -l $region 15 | 16 | #########-----Create resources---------###### 17 | 18 | #Creating vnet and VMs 19 | 20 | Write-Host "Adding subnet configuration" ` 21 | -ForegroundColor "Yellow" -BackgroundColor "Black" 22 | $workloads = New-AzVirtualNetworkSubnetConfig ` 23 | -Name 'privateSubnet' ` 24 | -AddressPrefix 10.0.0.0/24 25 | 26 | New-AzVirtualNetwork ` 27 | -ResourceGroupName $rg ` 28 | -Location $region ` 29 | -Name "prod-eus-vnet" ` 30 | -AddressPrefix 10.0.0.0/16 ` 31 | -Subnet $workloads 32 | 33 | Write-Host "Creating Linux VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 34 | $linuxVm = New-AzVM -Name 'linux-prod-server' ` 35 | -ResourceGroupName $rg ` 36 | -Location $region ` 37 | -Size 'Standard_B1s' ` 38 | -Image UbuntuLTS ` 39 | -VirtualNetworkName prod-eus-vnet ` 40 | -SubnetName 'privateSubnet' ` 41 | -Credential $credential 42 | $windowsVm = New-AzVM -Name 'win-prod-server' ` 43 | -ResourceGroupName $rg ` 44 | -Location $region ` 45 | -Size 'Standard_D2s_v3' ` 46 | -VirtualNetworkName prod-eus-vnet ` 47 | -SubnetName 'privateSubnet' ` 48 | -Credential $credential 49 | 50 | $fqdn = $linuxVm.FullyQualifiedDomainName 51 | Write-Host "Linux VM DNS name : $fqdn " 52 | $fqdn = $windowsVm.FullyQualifiedDomainName 53 | Write-Host "Windows VM DNS name : $fqdn " 54 | -------------------------------------------------------------------------------- /v1/Azure Load Balancer/jumpbox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install sshpass -y 4 | colors=(red green blue) 5 | for i in {0..2} 6 | do 7 | j=$(($i + 4)) 8 | ip="10.0.2.$j" 9 | sshpass -p "VMP@55w0rd" \ 10 | ssh -o StrictHostKeyChecking=no kodekloud@$ip bash -c \ 11 | "'export VAR=$i 12 | printenv | grep VAR 13 | echo "Setting up webserver-0$i VM" 14 | sudo apt install apache2 -y 15 | sudo chmod -R -v 777 /var/www/ 16 | sudo curl "https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/Azure%20Load%20Balancer/sample.html" > /var/www/html/index.html 17 | sed -i "s/PAGECOLOR/${colors[$i]}/g" /var/www/html/index.html 18 | exit 19 | '" 20 | done 21 | -------------------------------------------------------------------------------- /v1/Azure Load Balancer/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | #Load Balancing Lab - Infra only script 2 | 3 | # LB is not included in the scrip 4 | 5 | Clear-Host 6 | #Variables 7 | $region = "eastus" 8 | $username = "kodekloud" #username for the VM 9 | $plainPassword = "VMP@55w0rd" #your VM password 10 | $VMSize = "Standard_B1s" 11 | 12 | #Creating VM credential; use your own password and username by changing the variables 13 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 14 | 15 | 16 | #Create RG 17 | $rg = Read-Host "(new)Resource group name" 18 | New-AzResourceGroup -n $rg -l $region 19 | 20 | #########-----Create resources---------###### 21 | 22 | #Creating vnet 23 | 24 | Write-Host "Adding subnet configuration" ` 25 | -ForegroundColor "Yellow" -BackgroundColor "Black" 26 | 27 | $jumpBox = New-AzVirtualNetworkSubnetConfig ` 28 | -Name 'jumpboxSubnet' ` 29 | -AddressPrefix 10.0.1.0/24 30 | 31 | $webServers = New-AzVirtualNetworkSubnetConfig ` 32 | -Name 'webSubnet' ` 33 | -AddressPrefix 10.0.2.0/24 34 | 35 | Write-Host "Creating eus-web-dev" ` 36 | -ForegroundColor "Yellow" -BackgroundColor "Black" 37 | 38 | $vnet = New-AzVirtualNetwork ` 39 | -ResourceGroupName $rg ` 40 | -Location $region ` 41 | -Name "eus-web-dev" ` 42 | -AddressPrefix 10.0.0.0/16 ` 43 | -Subnet $jumpBox, $webServers 44 | 45 | $webRule = New-AzNetworkSecurityRuleConfig -Name web-rule -Description "Allow HTTP" -Access Allow ` 46 | -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * ` 47 | -DestinationAddressPrefix * -DestinationPortRange 80 48 | 49 | $networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName $rg ` 50 | -Location $region -Name "webNSG" -SecurityRules $rdpRule 51 | 52 | Set-AzVirtualNetworkSubnetConfig -Name webSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.2.0/24" ` 53 | -NetworkSecurityGroup $networkSecurityGroup 54 | 55 | $vnet | Set-AzVirtualNetwork 56 | 57 | Write-Host "Creating availability set" ` 58 | -ForegroundColor "Yellow" -BackgroundColor "Black" 59 | 60 | $avSet = New-AzAvailabilitySet -ResourceGroupName $rg -Name "az-web-set" ` 61 | -Location $region -PlatformUpdateDomainCount 3 ` 62 | -PlatformFaultDomainCount 3 -Sku "Aligned" 63 | 64 | for($i=1; $i -le 3; $i++){ 65 | 66 | $webServersNIC = New-AzNetworkInterface -Name "webserver-0$i-nic" -ResourceGroupName $rg ` 67 | -Location $region -SubnetId $vnet.Subnets[1].Id 68 | 69 | Write-Host "----------------------------------------------------" ` 70 | -ForegroundColor "Yellow" -BackgroundColor "Black" 71 | 72 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 73 | 74 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 75 | 76 | $VirtualMachine = New-AzVMConfig -VMName "webserver-0$i" -VMSize $VMSize -AvailabilitySetId $avSet.Id 77 | 78 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 79 | 80 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 81 | -Linux -ComputerName "webserver0$i" -Credential $credential 82 | 83 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $webServersNIC.Id 84 | 85 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 86 | -PublisherName 'Canonical' ` 87 | -Offer '0001-com-ubuntu-server-jammy' ` 88 | -Skus '22_04-lts-gen2' ` 89 | -Version latest 90 | 91 | Write-Host "Creating VM webserver-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 92 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 93 | 94 | } 95 | 96 | 97 | Write-Host "Creating jumpbox VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 98 | $jumpVm = New-AzVM -Name jumpbox-vm ` 99 | -ResourceGroupName $rg ` 100 | -Location $region ` 101 | -Size 'Standard_B1s' ` 102 | -Image UbuntuLTS ` 103 | -VirtualNetworkName eus-web-dev ` 104 | -SubnetName jumpboxSubnet ` 105 | -Credential $credential ` 106 | -PublicIpAddressName 'jumpbox-pip' 107 | 108 | Write-Host "Configuring VMs..." -BackgroundColor Yellow -ForegroundColor White 109 | 110 | $Params = @{ 111 | ResourceGroupName = $rg 112 | VMName = 'jumpbox-vm' 113 | Name = 'CustomScript' 114 | Publisher = 'Microsoft.Azure.Extensions' 115 | ExtensionType = 'CustomScript' 116 | TypeHandlerVersion = '2.1' 117 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/Azure%20Load%20Balancer/jumpbox.sh'); commandToExecute = './jumpbox.sh'} 118 | } 119 | Set-AzVMExtension @Params 120 | 121 | Write-Host "Deployment Completed!!" -BackgroundColor Yellow -ForegroundColor White 122 | 123 | $fqdn = $jumpVm.FullyQualifiedDomainName 124 | Write-Host "Jumpbox VM DNS name : $fqdn " 125 | for ($i=1; $i -le 3; $i++){ 126 | 127 | $vmIP= (Get-AzNetworkInterface -Name "webserver-0$i-nic").IpConfigurations.PrivateIPAddress 128 | Write-Host "Private IP (webserver-0$i) :$vmIP" 129 | 130 | } 131 | -------------------------------------------------------------------------------- /v1/Azure Load Balancer/sample.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Hello world

5 | 6 | 7 | -------------------------------------------------------------------------------- /v1/GatewayTransit/configureSpoke1.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install apache2 -y 4 | sudo chown -R -v 777 /var/www/ 5 | echo "

Hi from Spoke-1

" > /var/www/html/index.html 6 | sudo systemctl start apache2 7 | sudo systemctl enable apache2 8 | echo "Configuration done" 9 | -------------------------------------------------------------------------------- /v1/GatewayTransit/configureSpoke2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo apt update -y 3 | sudo apt install apache2 -y 4 | sudo chown -R -v 777 /var/www/ 5 | echo "

Hi from Spoke-2

" > /var/www/html/index.html 6 | sudo systemctl start apache2 7 | sudo systemctl enable apache2 8 | echo "Configuration done" 9 | -------------------------------------------------------------------------------- /v1/GatewayTransit/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | $rg = read-host "(new) Resource Group Name" 2 | $region = "eastus" 3 | $username = "kodekloud" #username for the VM 4 | $plainPassword = "VMP@55w0rd" #your VM password 5 | 6 | 7 | #Creating VM credential; use your own password and username by changing the variables if needed 8 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 9 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 10 | 11 | #Create RG 12 | New-AzResourceGroup -n $rg -l $region 13 | 14 | 15 | #--------------------------Spoke 1-----------------------# 16 | 17 | Write-Host "Adding spoke-1 subnet configuration" ` 18 | -ForegroundColor "Yellow" -BackgroundColor "Black" 19 | 20 | $s1Subnet = New-AzVirtualNetworkSubnetConfig ` 21 | -Name 'default' ` 22 | -AddressPrefix 10.0.0.0/24 23 | 24 | New-AzVirtualNetwork ` 25 | -ResourceGroupName $rg ` 26 | -Location eastus ` 27 | -Name "spoke-1-vnet" ` 28 | -AddressPrefix 10.0.0.0/16 ` 29 | -Subnet $s1Subnet 30 | 31 | $spoke1Vm = New-AzVM -Name 'spoke-1-vm' ` 32 | -ResourceGroupName $rg ` 33 | -Location eastus ` 34 | -Size 'Standard_B1s' ` 35 | -Image UbuntuLTS ` 36 | -VirtualNetworkName spoke-1-vnet ` 37 | -SubnetName 'default' ` 38 | -Credential $credential ` 39 | 40 | Write-Host "Configuring spoke-1 VM" -BackgroundColor Green -ForegroundColor White 41 | 42 | $Params = @{ 43 | ResourceGroupName = $rg 44 | VMName = 'spoke-1-vm' 45 | Name = 'CustomScript' 46 | Publisher = 'Microsoft.Azure.Extensions' 47 | ExtensionType = 'CustomScript' 48 | TypeHandlerVersion = '2.1' 49 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/GatewayTransit/configureSpoke1.sh'); commandToExecute = './configureSpoke1.sh'} 50 | } 51 | 52 | 53 | #--------------------------Spoke 2-----------------------# 54 | 55 | Write-Host "Adding spoke-2 subnet configuration" ` 56 | -ForegroundColor "Yellow" -BackgroundColor "Black" 57 | 58 | $s2Subnet = New-AzVirtualNetworkSubnetConfig ` 59 | -Name 'default' ` 60 | -AddressPrefix 10.1.0.0/24 61 | 62 | New-AzVirtualNetwork ` 63 | -ResourceGroupName $rg ` 64 | -Location westus ` 65 | -Name "spoke-2-vnet" ` 66 | -AddressPrefix 10.1.0.0/16 ` 67 | -Subnet $s2Subnet 68 | 69 | $spoke2Vm = New-AzVM -Name 'spoke-2-vm' ` 70 | -ResourceGroupName $rg ` 71 | -Location westus ` 72 | -Size 'Standard_B1s' ` 73 | -Image UbuntuLTS ` 74 | -VirtualNetworkName spoke-2-vnet ` 75 | -SubnetName 'default' ` 76 | -Credential $credential ` 77 | 78 | 79 | Write-Host "Configuring spoke-2 VM" -BackgroundColor Green -ForegroundColor White 80 | 81 | $Params = @{ 82 | ResourceGroupName = $rg 83 | VMName = 'spoke-2-vm' 84 | Name = 'CustomScript' 85 | Publisher = 'Microsoft.Azure.Extensions' 86 | ExtensionType = 'CustomScript' 87 | TypeHandlerVersion = '2.1' 88 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-azure/main/GatewayTransit/configureSpoke2.sh'); commandToExecute = './configureSpoke2.sh'} 89 | } 90 | 91 | 92 | #---------------------------Creating hub resources-----------------------# 93 | 94 | $hubSubnet = New-AzVirtualNetworkSubnetConfig ` 95 | -Name 'default' ` 96 | -AddressPrefix 10.2.1.0/24 97 | 98 | $hubGateway = New-AzVirtualNetworkSubnetConfig ` 99 | -Name 'GatewaySubnet' ` 100 | -AddressPrefix 10.2.0.0/28 101 | 102 | New-AzVirtualNetwork ` 103 | -ResourceGroupName $rg ` 104 | -Location eastus ` 105 | -Name "hub-vnet" ` 106 | -AddressPrefix 10.2.0.0/16 ` 107 | -Subnet $hubSubnet, $hubGateway 108 | 109 | $hubgwpip= New-AzPublicIpAddress ` 110 | -Name pip-vpn-hub ` 111 | -ResourceGroupName $rg ` 112 | -Location 'East US' ` 113 | -AllocationMethod Dynamic 114 | 115 | $vnet = Get-AzVirtualNetwork ` 116 | -Name hub-vnet ` 117 | -ResourceGroupName $rg 118 | 119 | $subnet = Get-AzVirtualNetworkSubnetConfig ` 120 | -Name 'GatewaySubnet' ` 121 | -VirtualNetwork $vnet 122 | 123 | $gwipconfig = New-AzVirtualNetworkGatewayIpConfig ` 124 | -Name 'hub-vpngw' ` 125 | -SubnetId $subnet.Id ` 126 | -PublicIpAddressId $hubgwpip.Id 127 | 128 | New-AzVirtualNetworkGateway ` 129 | -Name hub-vpngw ` 130 | -ResourceGroupName $rg ` 131 | -Location 'East US' ` 132 | -IpConfigurations $gwipconfig ` 133 | -GatewayType Vpn ` 134 | -VpnType RouteBased ` 135 | -GatewaySku VpnGw1 136 | -------------------------------------------------------------------------------- /v1/Peering/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | 2 | Clear-Host 3 | #Variables 4 | $rg = read-host "(new) Resource Group Name" 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | 9 | #Creating VM credential; use your own password and username by changing the variables if needed 10 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 11 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 12 | 13 | #Create RG 14 | New-AzResourceGroup -n $rg -l $region 15 | 16 | #########-----Create resources---------###### 17 | 18 | #Creating vnet and VMs 19 | Write-Host "Adding EUS subnet configuration" ` 20 | -ForegroundColor "Yellow" -BackgroundColor "Black" 21 | 22 | $eusSubnet = New-AzVirtualNetworkSubnetConfig ` 23 | -Name 'default' ` 24 | -AddressPrefix 10.0.0.0/24 25 | 26 | New-AzVirtualNetwork ` 27 | -ResourceGroupName $rg ` 28 | -Location eastus ` 29 | -Name "eus-vnet" ` 30 | -AddressPrefix 10.0.0.0/16 ` 31 | -Subnet $eusSubnet 32 | 33 | Write-Host "Adding WUS subnet configuration" ` 34 | -ForegroundColor "Yellow" -BackgroundColor "Black" 35 | $wusSubnet = New-AzVirtualNetworkSubnetConfig ` 36 | -Name 'privateSubnet' ` 37 | -AddressPrefix 192.168.1.0/24 38 | 39 | New-AzVirtualNetwork ` 40 | -ResourceGroupName $rg ` 41 | -Location westus ` 42 | -Name "wus-vnet" ` 43 | -AddressPrefix 192.168.0.0/16 ` 44 | -Subnet $wusSubnet 45 | 46 | Write-Host "Creating East US VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 47 | $eusVm = New-AzVM -Name 'eus-prod-server' ` 48 | -ResourceGroupName $rg ` 49 | -Location eastus ` 50 | -Size 'Standard_B1s' ` 51 | -Image UbuntuLTS ` 52 | -VirtualNetworkName eus-vnet ` 53 | -SubnetName 'default' ` 54 | -Credential $credential ` 55 | -PublicIpAddressName 'eus-vm-pip' 56 | 57 | Write-Host "Creating West US VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 58 | $wusVm = New-AzVM -Name 'wus-prod-server' ` 59 | -ResourceGroupName $rg ` 60 | -Location westus ` 61 | -Image UbuntuLTS ` 62 | -Size 'Standard_B1s' ` 63 | -VirtualNetworkName wus-vnet ` 64 | -SubnetName 'default' ` 65 | -Credential $credential 66 | 67 | $fqdn = $eusVm.FullyQualifiedDomainName 68 | Write-Host "East US VM DNS name : $fqdn " 69 | $fqdn = $wusVm.FullyQualifiedDomainName 70 | Write-Host "West US VM DNS name : $fqdn " 71 | -------------------------------------------------------------------------------- /v1/VNet-to-VNet/lab-infra.ps1: -------------------------------------------------------------------------------- 1 | 2 | Clear-Host 3 | #Variables 4 | $rg = read-host "(new) Resource Group Name" 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | 9 | #Creating VM credential; use your own password and username by changing the variables if needed 10 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 11 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 12 | 13 | #Create RG 14 | New-AzResourceGroup -n $rg -l $region 15 | 16 | #########-----Create EUS resources---------###### 17 | 18 | 19 | Write-Host "Adding EUS subnet configuration" ` 20 | -ForegroundColor "Yellow" -BackgroundColor "Black" 21 | 22 | $eusSubnet = New-AzVirtualNetworkSubnetConfig ` 23 | -Name 'default' ` 24 | -AddressPrefix 10.0.1.0/24 25 | $eusGateway = New-AzVirtualNetworkSubnetConfig ` 26 | -Name 'GatewaySubnet' ` 27 | -AddressPrefix 10.0.0.0/28 28 | 29 | New-AzVirtualNetwork ` 30 | -ResourceGroupName $rg ` 31 | -Location eastus ` 32 | -Name "eus-vnet" ` 33 | -AddressPrefix 10.0.0.0/16 ` 34 | -Subnet $eusSubnet,$eusGateway 35 | 36 | Write-Host "Creating East US VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 37 | $eusVm = New-AzVM -Name 'eus-prod-server' ` 38 | -ResourceGroupName $rg ` 39 | -Location eastus ` 40 | -Size 'Standard_B1s' ` 41 | -Image UbuntuLTS ` 42 | -VirtualNetworkName eus-vnet ` 43 | -SubnetName 'default' ` 44 | -Credential $credential ` 45 | -PublicIpAddressName 'eus-vm-pip' 46 | 47 | 48 | $eusgwpip= New-AzPublicIpAddress ` 49 | -Name pip-vpn-eus ` 50 | -ResourceGroupName $rg ` 51 | -Location 'East US' ` 52 | -AllocationMethod Dynamic 53 | 54 | $vnet = Get-AzVirtualNetwork ` 55 | -Name eus-vnet ` 56 | -ResourceGroupName $rg 57 | 58 | $subnet = Get-AzVirtualNetworkSubnetConfig ` 59 | -Name 'GatewaySubnet' ` 60 | -VirtualNetwork $vnet 61 | 62 | $gwipconfig = New-AzVirtualNetworkGatewayIpConfig ` 63 | -Name vpngw-eus ` 64 | -SubnetId $subnet.Id ` 65 | -PublicIpAddressId $eusgwpip.Id 66 | 67 | New-AzVirtualNetworkGateway ` 68 | -Name vpngw-eus ` 69 | -ResourceGroupName $rg ` 70 | -Location 'East US' ` 71 | -IpConfigurations $gwipconfig ` 72 | -GatewayType Vpn ` 73 | -VpnType RouteBased ` 74 | -GatewaySku VpnGw1 75 | 76 | 77 | #########-----Create WUS resources---------###### 78 | 79 | Write-Host "Adding WUS subnet configuration" ` 80 | -ForegroundColor "Yellow" -BackgroundColor "Black" 81 | $wusSubnet = New-AzVirtualNetworkSubnetConfig ` 82 | -Name 'default' ` 83 | -AddressPrefix 192.168.1.0/24 84 | 85 | $wusGateway = New-AzVirtualNetworkSubnetConfig ` 86 | -Name 'GatewaySubnet' ` 87 | -AddressPrefix 192.168.0.0/28 88 | 89 | New-AzVirtualNetwork ` 90 | -ResourceGroupName $rg ` 91 | -Location westus ` 92 | -Name "wus-vnet" ` 93 | -AddressPrefix 192.168.0.0/16 ` 94 | -Subnet $wusSubnet,$wusGateway 95 | 96 | Write-Host "Creating West US VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 97 | $wusVm = New-AzVM -Name 'wus-prod-server' ` 98 | -ResourceGroupName $rg ` 99 | -Location westus ` 100 | -Image UbuntuLTS ` 101 | -Size 'Standard_B1s' ` 102 | -VirtualNetworkName wus-vnet ` 103 | -SubnetName 'default' ` 104 | -Credential $credential 105 | 106 | 107 | 108 | $wusgwpip= New-AzPublicIpAddress ` 109 | -Name pip-vpn-wus ` 110 | -ResourceGroupName $rg ` 111 | -Location 'West US' ` 112 | -AllocationMethod Dynamic 113 | 114 | $vnet = Get-AzVirtualNetwork ` 115 | -Name wus-vnet ` 116 | -ResourceGroupName $rg 117 | 118 | $subnet = Get-AzVirtualNetworkSubnetConfig ` 119 | -Name 'GatewaySubnet' ` 120 | -VirtualNetwork $vnet 121 | 122 | $gwipconfig = New-AzVirtualNetworkGatewayIpConfig ` 123 | -Name vpngw-wus ` 124 | -SubnetId $subnet.Id ` 125 | -PublicIpAddressId $wusgwpip.Id 126 | 127 | New-AzVirtualNetworkGateway ` 128 | -Name vpngw-wus ` 129 | -ResourceGroupName $rg ` 130 | -Location 'West US' ` 131 | -IpConfigurations $gwipconfig ` 132 | -GatewayType Vpn ` 133 | -VpnType RouteBased ` 134 | -GatewaySku VpnGw1 135 | 136 | $fqdn = $eusVm.FullyQualifiedDomainName 137 | Write-Host "East US VM DNS name : $fqdn " 138 | $fqdn = $wusVm.FullyQualifiedDomainName 139 | Write-Host "West US VM DNS name : $fqdn " 140 | -------------------------------------------------------------------------------- /v2/050- Administer Virtual Networking/nsg-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Preferences 2 | $WarningPreference = 'SilentlyContinue' 3 | $ErrorActionPreference = 'Break' 4 | 5 | #Variables 6 | $rg = "rg-nsg-workload-$(Get-Date -Format 'yyyyMMdd')" 7 | $region = "eastus" 8 | $username = "kodekloud" #username for the VM 9 | $plainPassword = "VMP@55w0rd" #your VM password 10 | 11 | #Creating VM credential; use your own password and username by changing the variables if needed 12 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 13 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 14 | 15 | #Create RG 16 | Write-Host "Adding resource group : $rg " -ForegroundColor "Yellow" -BackgroundColor "Black" 17 | New-AzResourceGroup -n $rg -l $region | Out-Null 18 | 19 | #########-----Create resources---------###### 20 | 21 | #Creating vnet and VMs in workload-a 22 | Write-Host "Adding workload-a network configuration" ` 23 | -ForegroundColor "Yellow" -BackgroundColor "Black" 24 | 25 | $workloadA = New-AzVirtualNetworkSubnetConfig ` 26 | -Name 'snet-workload-a' ` 27 | -AddressPrefix 192.168.1.0/24 28 | $workloadB = New-AzVirtualNetworkSubnetConfig ` 29 | -Name 'snet-workload-b' ` 30 | -AddressPrefix 192.168.2.0/24 31 | 32 | New-AzVirtualNetwork ` 33 | -ResourceGroupName $rg ` 34 | -Location eastus ` 35 | -Name "vnet-workloads" ` 36 | -AddressPrefix 192.168.0.0/16 ` 37 | -Subnet $workloadA,$workloadB | Out-Null 38 | 39 | 40 | 41 | for ($i = 1; $i -lt 3; $i++) { 42 | Write-Host "Creating workload-a-vm-$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 43 | $spAvm = New-AzVM -Name "workload-a-vm-$i" ` 44 | -ResourceGroupName $rg ` 45 | -Location eastus ` 46 | -Size 'Standard_B1s' ` 47 | -Image "Ubuntu2204" ` 48 | -VirtualNetworkName "vnet-workloads" ` 49 | -SubnetName 'snet-workload-a' ` 50 | -Credential $credential ` 51 | -PublicIpAddressName "workload-a-vm-$i-pip" ` 52 | -PublicIpSku Standard 53 | $fqdn = $spAvm.FullyQualifiedDomainName 54 | Write-Host "workload-a-vm-$i FQDN : $fqdn " -ForegroundColor Green 55 | Write-Host "Creating workload-b-vm-$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 56 | $spBvm = New-AzVM -Name "workload-b-vm-$i" ` 57 | -ResourceGroupName $rg ` 58 | -Location eastus ` 59 | -Image "Ubuntu2204" ` 60 | -Size 'Standard_B1s' ` 61 | -VirtualNetworkName "vnet-workloads" ` 62 | -SubnetName 'snet-workload-b' ` 63 | -Credential $credential ` 64 | -PublicIpAddressName "workload-b-vm-$i-pip" ` 65 | -PublicIpSku Standard 66 | $fqdn = $spBvm.FullyQualifiedDomainName 67 | Write-Host "workload-b-vm-$i FQDN: $fqdn " -ForegroundColor Green 68 | } -------------------------------------------------------------------------------- /v2/060-Administer Intersite Connectivity/peering-pref-infra.ps1: -------------------------------------------------------------------------------- 1 | #Pref 2 | $WarningPreference = 'SilentlyContinue' 3 | 4 | #Variables 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | $VMSize = "Standard_B1s" 9 | 10 | #Creating VM credential; use your own password and username by changing the variables 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 13 | 14 | 15 | #Create RG 16 | $rg = "rg-vnet-peering-$(Get-Date -Format 'yyyyMMdd')" 17 | New-AzResourceGroup -n $rg -l $region 18 | 19 | Write-Host "Creating EUS VM" -ForegroundColor Green 20 | New-AzVm ` 21 | -ResourceGroupName $rg ` 22 | -Name 'vm-eus' ` 23 | -Location 'East US' ` 24 | -image Ubuntu2204 ` 25 | -size $VMSize ` 26 | -PublicIpAddressName 'eus-vm-pip' ` 27 | -OpenPorts 22 ` 28 | -Credential $credential ` 29 | -VirtualNetworkName 'vnet-eus' ` 30 | -AddressPrefix '192.168.0.0/24' ` 31 | -SubnetName 'default' ` 32 | -SubnetAddressPrefix '192.168.0.0/24' 33 | 34 | Write-Host "Creating WUS VM" -ForegroundColor Green 35 | New-AzVm ` 36 | -ResourceGroupName $rg ` 37 | -Name 'vm-wus' ` 38 | -Location 'West US' ` 39 | -image Ubuntu2204 ` 40 | -size $VMSize ` 41 | -PublicIpAddressName 'wus-vm-pip' ` 42 | -OpenPorts 22 ` 43 | -Credential $credential ` 44 | -VirtualNetworkName 'vnet-wus' ` 45 | -AddressPrefix '192.168.1.0/24' ` 46 | -SubnetName 'default' ` 47 | -SubnetAddressPrefix '192.168.1.0/24' -------------------------------------------------------------------------------- /v2/060-Administer Intersite Connectivity/service-endpoints-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Preferences 2 | $WarningPreference = 'SilentlyContinue' 3 | $ErrorActionPreference = 'Break' 4 | 5 | #Variables 6 | $rg = "rg-se-workload-$(Get-Date -Format 'yyyyMMdd')" 7 | $region = "eastus" 8 | $username = "kodekloud" #username for the VM 9 | $plainPassword = "VMP@55w0rd" #your VM password 10 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 11 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 12 | #Create VM 13 | Write-Host "Creating VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 14 | $spAvm = New-AzVM -Name "vm-01" ` 15 | -ResourceGroupName $rg ` 16 | -Location eastus ` 17 | -Size 'Standard_B1s' ` 18 | -Image "Ubuntu2204" ` 19 | -VirtualNetworkName "vnet-01" ` 20 | -SubnetName 'default' ` 21 | -Credential $credential ` 22 | -PublicIpAddressName "vm-01-pip" ` 23 | -PublicIpSku Standard 24 | $fqdn = $spAvm.FullyQualifiedDomainName 25 | Write-Host "workload-a-vm-$i FQDN : $fqdn " -ForegroundColor Green 26 | 27 | #Create storage 28 | Write-Host "Creating storage" -ForegroundColor "Yellow" -BackgroundColor "Black" 29 | New-AzStorageAccount ` 30 | -ResourceGroupName $rg ` 31 | -Name "st$(Get-Random)$(Get-Date -Format 'yyyyMMdd')" ` 32 | -Location $region ` 33 | -Kind StorageV2 ` 34 | -AllowBlobPublicAccess $true ` 35 | -SkuName Standard_LRS -------------------------------------------------------------------------------- /v2/070-Administer Network Traffic/appgw-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Pref 2 | $WarningPreference = 'SilentlyContinue' 3 | 4 | #Variables 5 | $rg = "rg-appgw-$(Get-Date -Format 'yyyyMMdd')" 6 | $region = "eastus" 7 | $username = "kodekloud" #username for the VM 8 | $plainPassword = "VMP@55w0rd" #your VM password 9 | 10 | #Creating VM credential; use your own password and username by changing the variables if needed 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 13 | #Pool server function 14 | function Deploy-PoolServers { 15 | [CmdletBinding()] 16 | param ( 17 | # color-code 18 | [Parameter(Mandatory = $true)] 19 | [String] 20 | $Color, 21 | 22 | # Subnet 23 | [Parameter(Mandatory = $true)] 24 | [String] 25 | $SubnetPointer 26 | ) 27 | #Variables 28 | $rg = "rg-appgw-$(Get-Date -Format 'yyyyMMdd')" 29 | $region = "eastus" 30 | $username = "kodekloud" #username for the VM 31 | $plainPassword = "VMP@55w0rd" #your VM password 32 | 33 | #Creating VM credential; use your own password and username by changing the variables if needed 34 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 35 | Write-Host "Creating $Color color vms" ` 36 | -ForegroundColor "Yellow" -BackgroundColor "Black" 37 | for ($i = 1; $i -le 2; $i++) { 38 | 39 | $workloadNIC = New-AzNetworkInterface -Name "$Color-0$i-nic" -ResourceGroupName $rg ` 40 | -Location $region -SubnetId $vnet.Subnets[$SubnetPointer].Id 41 | 42 | Write-Host "----------------------------------------------------" ` 43 | -ForegroundColor "Yellow" -BackgroundColor "Black" 44 | 45 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 46 | 47 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 48 | 49 | $VirtualMachine = New-AzVMConfig -VMName "$Color-0$i" -VMSize "Standard_B1s" 50 | 51 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 52 | 53 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 54 | -Linux -ComputerName "$($Color)0$($i)" -Credential $credential 55 | 56 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $workloadNIC.Id 57 | 58 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 59 | -PublisherName 'Canonical' ` 60 | -Offer '0001-com-ubuntu-server-jammy' ` 61 | -Skus '22_04-lts-gen2' ` 62 | -Version latest 63 | 64 | Write-Host "Creating VM $Color-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 65 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 66 | 67 | } 68 | 69 | } 70 | 71 | function Find-PoolServerIP { 72 | [CmdletBinding()] 73 | param ( 74 | # Color 75 | [Parameter(Mandatory = $true)] 76 | [String] 77 | $Color 78 | 79 | ) 80 | for ($i = 1; $i -le 2; $i++) { 81 | 82 | $vmIP = (Get-AzNetworkInterface -Name "$($Color)-0$i-nic").IpConfigurations.PrivateIPAddress 83 | Write-Host "Private IP ($($Color)-0$i) :$vmIP" 84 | 85 | } 86 | } 87 | 88 | #Create RG 89 | New-AzResourceGroup -n $rg -l $region 90 | 91 | #########-----Create resources---------###### 92 | 93 | #Creating vnet 94 | 95 | Write-Host "Adding subnet configuration" ` 96 | -ForegroundColor "Yellow" -BackgroundColor "Black" 97 | 98 | $jumpBox = New-AzVirtualNetworkSubnetConfig ` 99 | -Name 'jumpboxSubnet' ` 100 | -AddressPrefix 10.0.0.0/24 101 | 102 | $greenSubnet = New-AzVirtualNetworkSubnetConfig ` 103 | -Name 'greenSubnet' ` 104 | -AddressPrefix 10.0.1.0/24 105 | 106 | $redSubnet = New-AzVirtualNetworkSubnetConfig ` 107 | -Name 'redSubnet' ` 108 | -AddressPrefix 10.0.2.0/24 109 | 110 | $blueSubnet = New-AzVirtualNetworkSubnetConfig ` 111 | -Name 'blueSubnet' ` 112 | -AddressPrefix 10.0.3.0/24 113 | 114 | Write-Host "Creating color-web-vnet" ` 115 | -ForegroundColor "Yellow" -BackgroundColor "Black" 116 | 117 | $vnet = New-AzVirtualNetwork ` 118 | -ResourceGroupName $rg ` 119 | -Location $region ` 120 | -Name "color-web-vnet" ` 121 | -AddressPrefix 10.0.0.0/16 ` 122 | -Subnet $jumpBox, $greenSubnet, $redSubnet, $blueSubnet 123 | 124 | #---------------------------------------------------# 125 | 126 | #-------------------NSG--------------------------------# 127 | 128 | $webRule = New-AzNetworkSecurityRuleConfig -Name web-rule -Description "Allow HTTP" -Access Allow ` 129 | -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * ` 130 | -DestinationAddressPrefix * -DestinationPortRange 80 131 | 132 | $networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName $rg ` 133 | -Location $region -Name "appGwNSG" -SecurityRules $webRule 134 | 135 | Set-AzVirtualNetworkSubnetConfig -Name greenSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.1.0/24" ` 136 | -NetworkSecurityGroup $networkSecurityGroup 137 | 138 | Set-AzVirtualNetworkSubnetConfig -Name redSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.2.0/24" ` 139 | -NetworkSecurityGroup $networkSecurityGroup 140 | 141 | Set-AzVirtualNetworkSubnetConfig -Name blueSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.3.0/24" ` 142 | -NetworkSecurityGroup $networkSecurityGroup 143 | 144 | $vnet | Set-AzVirtualNetwork 145 | 146 | #------------Creating pool servers---------------------------------------# 147 | 148 | Deploy-PoolServers -Color 'green' -SubnetPointer 1 149 | Deploy-PoolServers -Color 'red' -SubnetPointer 2 150 | Deploy-PoolServers -Color 'blue' -SubnetPointer 3 151 | 152 | #---------------------------------------------------# 153 | 154 | #---------------------Jumpbox------------------------------# 155 | 156 | Write-Host "Creating jumpbox VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 157 | $jumpVm = New-AzVM -Name jumpbox-vm ` 158 | -ResourceGroupName $rg ` 159 | -Location $region ` 160 | -Size 'Standard_B1s' ` 161 | -Image Ubuntu2204 ` 162 | -VirtualNetworkName color-web-vnet ` 163 | -SubnetName jumpboxSubnet ` 164 | -PublicIpAddressName 'jumpbox-appgw-pip' ` 165 | -Credential $credential 166 | 167 | Write-Host "Running script on jumpbox..." -BackgroundColor Green -ForegroundColor White 168 | 169 | $Params = @{ 170 | ResourceGroupName = $rg 171 | VMName = 'jumpbox-vm' 172 | Name = 'CustomScript' 173 | Publisher = 'Microsoft.Azure.Extensions' 174 | ExtensionType = 'CustomScript' 175 | TypeHandlerVersion = '2.1' 176 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-az500/main/000-Code%20files/AppGateway/jumpbox.sh'); commandToExecute = './jumpbox.sh' } 177 | } 178 | Set-AzVMExtension @Params 179 | 180 | #---------------------------------------------------# 181 | 182 | #---------------------Output------------------------------# 183 | 184 | Write-Host "Deployment Completed!!" -BackgroundColor Green -ForegroundColor White 185 | 186 | $fqdn = $jumpVm.FullyQualifiedDomainName 187 | Write-Host "Jumpbox VM DNS name : $fqdn " 188 | Find-PoolServerIP -Color green 189 | Find-PoolServerIP -Color blue 190 | Find-PoolServerIP -Color red 191 | Write-Host "Use username: $username and password: $plainPassword to login to any VMs" ` 192 | -ForegroundColor "Green" -BackgroundColor "White" -------------------------------------------------------------------------------- /v2/070-Administer Network Traffic/loadbalancer-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Pref 2 | $WarningPreference = 'SilentlyContinue' 3 | 4 | #Variables 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | $VMSize = "Standard_B1s" 9 | 10 | #Creating VM credential; use your own password and username by changing the variables 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | 13 | #Create RG 14 | $rg = "rg-azlb-$(Get-Date -Format 'yyyyMMdd')" 15 | New-AzResourceGroup -n $rg -l $region 16 | 17 | #########-----Create resources---------###### 18 | 19 | #Creating vnet 20 | 21 | Write-Host "Adding subnet configuration" ` 22 | -ForegroundColor "Yellow" -BackgroundColor "Black" 23 | 24 | $jumpBox = New-AzVirtualNetworkSubnetConfig ` 25 | -Name 'jumpboxSubnet' ` 26 | -AddressPrefix 10.0.1.0/24 27 | 28 | $webServers = New-AzVirtualNetworkSubnetConfig ` 29 | -Name 'webSubnet' ` 30 | -AddressPrefix 10.0.2.0/24 31 | 32 | Write-Host "Creating eus-web-dev" ` 33 | -ForegroundColor "Yellow" -BackgroundColor "Black" 34 | 35 | $vnet = New-AzVirtualNetwork ` 36 | -ResourceGroupName $rg ` 37 | -Location $region ` 38 | -Name "eus-web-dev" ` 39 | -AddressPrefix 10.0.0.0/16 ` 40 | -Subnet $jumpBox, $webServers 41 | 42 | $webRule = New-AzNetworkSecurityRuleConfig -Name web-rule -Description "Allow HTTP" -Access Allow ` 43 | -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * ` 44 | -DestinationAddressPrefix * -DestinationPortRange 80 45 | 46 | $networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName $rg ` 47 | -Location $region -Name "webNSG" -SecurityRules $webrule 48 | 49 | Set-AzVirtualNetworkSubnetConfig -Name webSubnet -VirtualNetwork $vnet -AddressPrefix "10.0.2.0/24" ` 50 | -NetworkSecurityGroup $networkSecurityGroup 51 | 52 | $vnet | Set-AzVirtualNetwork 53 | 54 | Write-Host "Creating availability set" ` 55 | -ForegroundColor "Yellow" -BackgroundColor "Black" 56 | 57 | $avSet = New-AzAvailabilitySet -ResourceGroupName $rg -Name "az-web-set" ` 58 | -Location $region -PlatformUpdateDomainCount 3 ` 59 | -PlatformFaultDomainCount 3 -Sku "Aligned" 60 | 61 | for($i=1; $i -le 3; $i++){ 62 | 63 | $webServersNIC = New-AzNetworkInterface -Name "webserver-0$i-nic" -ResourceGroupName $rg ` 64 | -Location $region -SubnetId $vnet.Subnets[1].Id 65 | 66 | Write-Host "----------------------------------------------------" ` 67 | -ForegroundColor "Yellow" -BackgroundColor "Black" 68 | 69 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 70 | 71 | Write-Host "Setting VM config" -ForegroundColor "Yellow" -BackgroundColor "Black" 72 | 73 | $VirtualMachine = New-AzVMConfig -VMName "webserver-0$i" -VMSize $VMSize -AvailabilitySetId $avSet.Id 74 | 75 | Write-Host "Setting OS Profile" -ForegroundColor "Yellow" -BackgroundColor "Black" 76 | 77 | $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine ` 78 | -Linux -ComputerName "webserver0$i" -Credential $credential 79 | 80 | $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $webServersNIC.Id 81 | 82 | $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine ` 83 | -PublisherName 'Canonical' ` 84 | -Offer '0001-com-ubuntu-server-jammy' ` 85 | -Skus '22_04-lts-gen2' ` 86 | -Version latest 87 | 88 | Write-Host "Creating VM webserver-0$i" -ForegroundColor "Yellow" -BackgroundColor "Black" 89 | New-AzVM -ResourceGroupName $rg -Location $region -VM $VirtualMachine 90 | 91 | } 92 | 93 | 94 | Write-Host "Creating jumpbox VM" -ForegroundColor "Yellow" -BackgroundColor "Black" 95 | $jumpVm = New-AzVM -Name jumpbox-vm ` 96 | -ResourceGroupName $rg ` 97 | -Location $region ` 98 | -Size 'Standard_B1s' ` 99 | -Image Ubuntu2204 ` 100 | -VirtualNetworkName eus-web-dev ` 101 | -SubnetName jumpboxSubnet ` 102 | -Credential $credential ` 103 | -PublicIpAddressName 'jumpbox-pip' 104 | 105 | Write-Host "Configuring VMs..." -BackgroundColor Yellow -ForegroundColor White 106 | 107 | $Params = @{ 108 | ResourceGroupName = $rg 109 | VMName = 'jumpbox-vm' 110 | Name = 'CustomScript' 111 | Publisher = 'Microsoft.Azure.Extensions' 112 | ExtensionType = 'CustomScript' 113 | TypeHandlerVersion = '2.1' 114 | Settings = @{fileUris = @('https://raw.githubusercontent.com/rithinskaria/kodekloud-az500/main/000-Code%20files/Azure%20Load%20Balancer/jumpbox.sh'); commandToExecute = './jumpbox.sh'} 115 | } 116 | Set-AzVMExtension @Params 117 | 118 | Write-Host "Deployment Completed!!" -BackgroundColor Yellow -ForegroundColor White 119 | 120 | $fqdn = $jumpVm.FullyQualifiedDomainName 121 | Write-Host "Jumpbox VM DNS name : $fqdn " 122 | for ($i=1; $i -le 3; $i++){ 123 | 124 | $vmIP= (Get-AzNetworkInterface -Name "webserver-0$i-nic").IpConfigurations.PrivateIPAddress 125 | Write-Host "Private IP (webserver-0$i) :$vmIP" 126 | 127 | } -------------------------------------------------------------------------------- /v2/090-Administer Azure Virtual Machines/bastion-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Pref 2 | $WarningPreference = 'SilentlyContinue' 3 | 4 | #Variables 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | $VMSize = "Standard_B1s" 9 | 10 | #Creating VM credential; use your own password and username by changing the variables 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 13 | #Create RG 14 | $rg = "rg-remoteaccess-$(Get-Date -Format 'yyyyMMdd')" 15 | New-AzResourceGroup -n $rg -l $region 16 | 17 | #########-----Create resources---------###### 18 | 19 | #Creating vnet 20 | 21 | Write-Host "Adding subnet configuration" ` 22 | -ForegroundColor "Yellow" -BackgroundColor "Black" 23 | 24 | $windows = New-AzVirtualNetworkSubnetConfig ` 25 | -Name 'windows' ` 26 | -AddressPrefix 10.0.1.0/24 27 | 28 | $linux = New-AzVirtualNetworkSubnetConfig ` 29 | -Name 'linux' ` 30 | -AddressPrefix 10.0.2.0/24 31 | 32 | Write-Host "Creating vnet-remoteaccess" ` 33 | -ForegroundColor "Yellow" -BackgroundColor "Black" 34 | 35 | New-AzVirtualNetwork ` 36 | -ResourceGroupName $rg ` 37 | -Location $region ` 38 | -Name "vnet-remoteaccess" ` 39 | -AddressPrefix 10.0.0.0/16 ` 40 | -Subnet $windows, $linux | Out-Null 41 | 42 | #Create Windows VM 43 | New-AzVm ` 44 | -ResourceGroupName $rg ` 45 | -Name 'win-ra-vm' ` 46 | -Location $region ` 47 | -Image 'MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest' ` 48 | -VirtualNetworkName "vnet-remoteaccess" ` 49 | -SubnetName 'windows' ` 50 | -SecurityGroupName 'windows-nsg' ` 51 | -Credential $credential 52 | 53 | #Create Linux VM 54 | New-AzVm ` 55 | -ResourceGroupName $rg ` 56 | -Name 'linux-ra-vm' ` 57 | -Location $region ` 58 | -Image 'Ubuntu2204' ` 59 | -VirtualNetworkName "vnet-remoteaccess" ` 60 | -SubnetName 'linux' ` 61 | -SecurityGroupName 'linux-nsg' ` 62 | -Credential $credential ` 63 | -Size $VMSize -------------------------------------------------------------------------------- /v2/120-Administer Monitoring/monitoring-prep-infra.ps1: -------------------------------------------------------------------------------- 1 | #Pref 2 | $WarningPreference = 'SilentlyContinue' 3 | 4 | #Variables 5 | $region = "eastus" 6 | $username = "kodekloud" #username for the VM 7 | $plainPassword = "VMP@55w0rd" #your VM password 8 | $VMSize = "Standard_B1s" 9 | 10 | #Creating VM credential; use your own password and username by changing the variables 11 | $password = ConvertTo-SecureString $plainPassword -AsPlainText -Force 12 | $credential = New-Object System.Management.Automation.PSCredential ($username, $password); 13 | #Create RG 14 | $rg = "rg-secops-$(Get-Date -Format 'yyyyMMdd')" 15 | New-AzResourceGroup -n $rg -l $region 16 | 17 | ########-----Create resources---------###### 18 | 19 | #Creating vnet 20 | 21 | Write-Host "Adding subnet configuration" ` 22 | -ForegroundColor "Yellow" -BackgroundColor "Black" 23 | 24 | $windows = New-AzVirtualNetworkSubnetConfig ` 25 | -Name 'windows' ` 26 | -AddressPrefix 10.0.1.0/24 27 | 28 | $linux = New-AzVirtualNetworkSubnetConfig ` 29 | -Name 'linux' ` 30 | -AddressPrefix 10.0.2.0/24 31 | 32 | Write-Host "Creating vnet-workloads" ` 33 | -ForegroundColor "Yellow" -BackgroundColor "Black" 34 | 35 | New-AzVirtualNetwork ` 36 | -ResourceGroupName $rg ` 37 | -Location $region ` 38 | -Name "vnet-workloads" ` 39 | -AddressPrefix 10.0.0.0/16 ` 40 | -Subnet $windows, $linux | Out-Null 41 | 42 | #Create Windows VM 43 | Write-Host "Creating Windows VM" ` 44 | -ForegroundColor "Yellow" -BackgroundColor "Black" 45 | New-AzVm ` 46 | -ResourceGroupName $rg ` 47 | -Name 'win-ra-vm' ` 48 | -Location $region ` 49 | -Image 'MicrosoftWindowsServer:WindowsServer:2022-datacenter-azure-edition:latest' ` 50 | -VirtualNetworkName "vnet-workloads" ` 51 | -SubnetName 'windows' ` 52 | -SecurityGroupName 'windows-nsg' ` 53 | -Credential $credential 54 | 55 | #Create Linux VM 56 | Write-Host "Creating Linux VM" ` 57 | -ForegroundColor "Yellow" -BackgroundColor "Black" 58 | New-AzVm ` 59 | -ResourceGroupName $rg ` 60 | -Name 'linux-ra-vm' ` 61 | -Location $region ` 62 | -Image 'Ubuntu2204' ` 63 | -VirtualNetworkName "vnet-workloads" ` 64 | -SubnetName 'linux' ` 65 | -SecurityGroupName 'linux-nsg' ` 66 | -Credential $credential ` 67 | -Size $VMSize 68 | 69 | Write-Host "Creating App Service" ` 70 | -ForegroundColor "Yellow" -BackgroundColor "Black" 71 | 72 | $asp = New-AzAppServicePlan ` 73 | -ResourceGroupName $rg ` 74 | -Name "asp-$(Get-Random)" ` 75 | -Location $region ` 76 | -Tier Basic ` 77 | -WorkerSize Small 78 | New-AzWebApp ` 79 | -ResourceGroupName $rg ` 80 | -Name "demoApp$(Get-Random)" ` 81 | -Location $region ` 82 | -AppServicePlan $asp.Name 83 | --------------------------------------------------------------------------------