Infrastructure as Code using ARM - Windows Edge VM and Azure Container Registery.
Create an environment setting file in the root directory ie: .env.ps1
or .envrc
Default Environment Settings
Parameter | Default | Description |
---|---|---|
ARM_SUBSCRIPTION_ID | xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | Azure Subscription Id |
AZURE_LOCATION | CentralUS | Azure Region for Resources to be located |
Note: This can be performed via Portal UI or CloudShell (Bash/Powershell)
Provision using portal
Provision using bash
Note: Requires the use of direnv
Run Install Script for ARM Process
# Initialize the Modules
initials="<your_initials>"
install.sh $initials
Provision using powershell
Note: Requires the use of powershell
Run Install Script for ARM Process
# Initialize the Modules
$initials = "<your_initials>"
install.ps1 -Initials $initials
- Connect to the Edge VM from CloudShell
$vm = "<your_vm_name>"
$group = "<your_resourceGroup>"
$cred = get-credential
Enable-AzVMPSRemoting -Name $vm -ResourceGroup $group -Protocol https -OsType Windows
Enter-AzVM -name $vm -ResourceGroup $group -Credential $cred
-
Retrieve Connection String for Edge Device from the desired IoT Hub
-
Configure the Edge Runtime on the Edge VM
# Configure IOT Edge on Edge VM
$DeviceConnectionString = "<your_connection_string>"
. {Invoke-WebRequest -useb aka.ms/iotedge-win} | Invoke-Expression; `
Initialize-IoTEdge -Manual -DeviceConnectionString $DeviceConnectionString -ContainerOs Windows
Get-IoTEdgeLog
iotedge check
Enable the Azure Container Monitoring Solution.
stop-service iotedge
stop-service iotedge-moby
# Reconfigure the iotedge-moby Service to use the following executable path
C:\Program Files\iotedge-moby\dockerd.exe -H npipe:////./pipe/docker_engine -H 0.0.0.0:2376 --exec-opt isolation=process --run-service --data-root C:\ProgramData\iotedge-moby --exec-root C:\ProgramData\iotedge-moby\\exec-root
# Start the Container Service
start-service iotedge-moby
# Test the connections
docker -H npipe:////./pipe/docker_engine images
docker -H 0.0.0.0:2376 images
# Setup Environment Variable for Docker to connect to container service.
[System.Environment]::SetEnvironmentVariable("DOCKER_HOST", "npipe:////./pipe/docker_engine", [System.EnvironmentVariableTarget]::Machine)
# --> Logoff for Environment Variable to take effect
# Modify the config.yaml
# uri: 'npipe://./pipe/iotedge_moby_engine'
uri: 'npipe://./pipe/docker_engine'
# Start IoTEdge Service
start-service iotedge
# Check
iotedge check
The URI Listen and Connect URI Schemes can be modified from UNIX to HTTP in order to support .NET Framework Modules
Note: This is not recommended for a production scenario.
- Open the firewall rule to allow 15580 and 15581 and identify the IP Address
# Add Firewall Rule
New-NetFirewallRule -DisplayName "IoT Edge" -Direction Inbound -LocalPort 15580, 15581 -Protocol TCP -Action Allow
# Retrieve IP Address
ipconfig
- Edit the Configuration and modify the Connect and Listen URI's using the IP Address
C:\programdata\iotedge\config.yaml
Note: Use the IP ADDRESS from the results of
ipconfig
connect:
management_uri: "http://10.0.0.4:15580"
workload_uri: "http://10.0.0.4:15581"
listen:
management_uri: "http://10.0.0.4:15580"
workload_uri: "http://10.0.0.4:15581"
- Set the Environment Variable to access the iotedge cli tool and restart the service
Note: Use the IP ADDRESS from the results of
ipconfig
# Setup the Environment variable (requires logoff to apply)
[System.Environment]::SetEnvironmentVariable("IOTEDGE_HOST", "http://10.0.0.4:15580", [System.EnvironmentVariableTarget]::Machine)
# Restart the Iot Edge Service
restart-service iotedge