Run Azure IoT Edge on Ubuntu Virtual Machines
Applies to: IoT Edge 1.1
Important
IoT Edge 1.1 end of support date was December 13, 2022. Check the Microsoft Product Lifecycle for information about how this product, service, technology, or API is supported. For more information about updating to the latest version of IoT Edge, see Update IoT Edge.
The Azure IoT Edge runtime is what turns a device into an IoT Edge device. The runtime can be deployed on devices as small as a Raspberry Pi or as large as an industrial server. Once a device is configured with the IoT Edge runtime, you can start deploying business logic to it from the cloud.
To learn more about how the IoT Edge runtime works and what components are included, see Understand the Azure IoT Edge runtime and its architecture.
This article lists the steps to deploy an Ubuntu 18.04 LTS virtual machine with the Azure IoT Edge runtime installed and configured using a pre-supplied device connection string. The deployment is accomplished using a cloud-init based Azure Resource Manager template maintained in the iotedge-vm-deploy project repository.
On first boot, the virtual machine installs the latest version of the Azure IoT Edge runtime via cloud-init. It also sets a supplied connection string before the runtime starts, allowing you to easily configure and connect the IoT Edge device without the need to start an SSH or remote desktop session.
Deploy using Deploy to Azure Button
The Deploy to Azure Button allows for streamlined deployment of Azure Resource Manager templates maintained on GitHub. This section will demonstrate usage of the Deploy to Azure Button contained in the iotedge-vm-deploy project repository.
We will deploy an Azure IoT Edge enabled Linux VM using the iotedge-vm-deploy Azure Resource Manager template. To begin, click the button below:
On the newly launched window, fill in the available form fields:
Field Description Subscription The active Azure subscription to deploy the virtual machine into. Resource group An existing or newly created Resource Group to contain the virtual machine and it's associated resources. Region The geographic region to deploy the virtual machine into, this value defaults to the location of the selected Resource Group. DNS Label Prefix A required value of your choosing that is used to prefix the hostname of the virtual machine. Admin Username A username, which will be provided root privileges on deployment. Device Connection String A device connection string for a device that was created within your intended IoT Hub. VM Size The size of the virtual machine to be deployed. Ubuntu OS Version The version of the Ubuntu OS to be installed on the base virtual machine. Authentication Type Choose sshPublicKey or password depending on your preference. Admin Password or Key The value of the SSH Public Key or the value of the password depending on the choice of Authentication Type. When all fields have been filled in, click the button at the bottom to move to
Next : Review + create
where you can review the terms and click Create to begin the deployment.Verify that the deployment has completed successfully. A virtual machine resource should have been deployed into the selected resource group. Take note of the machine name, this should be in the format
vm-0000000000000
. Also, take note of the associated DNS Name, which should be in the format<dnsLabelPrefix>
.<location>
.cloudapp.azure.com.The DNS Name can be obtained from the Overview section of the newly deployed virtual machine within the Azure portal.
If you want to SSH into this VM after setup, use the associated DNS Name with the command:
ssh <adminUsername>@<DNS_Name>
Deploy from Azure CLI
Ensure that you have installed the Azure CLI iot extension with:
az extension add --name azure-iot
Next, if you're using Azure CLI on your desktop, start by logging in:
az login
If you have multiple subscriptions, select the subscription you'd like to use:
List your subscriptions:
az account list --output table
Copy the SubscriptionID field for the subscription you'd like to use.
Set your working subscription with the ID that you copied:
az account set -s <SubscriptionId>
Create a new resource group (or specify an existing one in the next steps):
az group create --name IoTEdgeResources --location westus2
Create a new virtual machine:
To use an authenticationType of
password
, see the example below:az deployment group create \ --resource-group IoTEdgeResources \ --template-uri "https://raw.githubusercontent.com/Azure/iotedge-vm-deploy/1.1/edgeDeploy.json" \ --parameters dnsLabelPrefix='my-edge-vm1' \ --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ --parameters authenticationType='password' \ --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ --parameters adminPasswordOrKey="<REPLACE_WITH_SECRET_PASSWORD>"
To authenticate with an SSH key, you may do so by specifying an authenticationType of
sshPublicKey
, then provide the value of the SSH key in the adminPasswordOrKey parameter. An example is shown below.#Generate the SSH Key ssh-keygen -m PEM -t rsa -b 4096 -q -f ~/.ssh/iotedge-vm-key -N "" #Create a VM using the iotedge-vm-deploy script az deployment group create \ --resource-group IoTEdgeResources \ --template-uri "https://raw.githubusercontent.com/Azure/iotedge-vm-deploy/1.1/edgeDeploy.json" \ --parameters dnsLabelPrefix='my-edge-vm1' \ --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ --parameters authenticationType='sshPublicKey' \ --parameters adminPasswordOrKey="$(< ~/.ssh/iotedge-vm-key.pub)"
Verify that the deployment has completed successfully. A virtual machine resource should have been deployed into the selected resource group. Take note of the machine name, this should be in the format
vm-0000000000000
. Also, take note of the associated DNS Name, which should be in the format<dnsLabelPrefix>
.<location>
.cloudapp.azure.com.The DNS Name can be obtained from the JSON-formatted output of the previous step, within the outputs section as part of the public SSH entry. The value of this entry can be used to SSH into to the newly deployed machine.
"outputs": { "public SSH": { "type": "String", "value": "ssh <adminUsername>@<DNS_Name>" } }
The DNS Name can also be obtained from the Overview section of the newly deployed virtual machine within the Azure portal.
If you want to SSH into this VM after setup, use the associated DNS Name with the command:
ssh <adminUsername>@<DNS_Name>
Next steps
Now that you have an IoT Edge device provisioned with the runtime installed, you can deploy IoT Edge modules.
If you are having problems with the IoT Edge runtime installing properly, check out the troubleshooting page.
To update an existing installation to the newest version of IoT Edge, see Update the IoT Edge security daemon and runtime.
If you'd like to open up ports to access the VM through SSH or other inbound connections, refer to the Azure Virtual Machines documentation on opening up ports and endpoints to a Linux VM