Code Monkey home page Code Monkey logo

azure-iot-edge-device-container's Introduction

azure-iot-edge-device-container

Docker Build Status Docker Pulls

An Azure IoT Edge Device in a Docker container with x64 / arm32 / aarch64 support

Create an Edge Device Container Instance using an existing device connection string

Obtain the device connection string: Edge Device Connection String

Start a container instance with:

docker run -it -d --privileged -e connectionString='<IoTHubDeviceConnectionString>' toolboc/azure-iot-edge-device-container

Create a self-provisioning Edge Device Container Instance

Create an Azure IoT Hub

Install the Azure-Cli

Run az login to sign in with the azure cli and set the appropriate subscription with:

az account set --subscription

Create a Service Principal for your subscription with the azure cli:

az ad sp create-for-rbac --name <name>

You should see output similar to:

{
"appId": "12345678-1234-1234-1234-1234567890ab",
"displayName": "azure-iot-edge-device-container-sp",
"name": "http://azure-iot-edge-device-container-sp",
"password": "MyPassword",
"tenant": "abcdefgh-abcd-abcd-abcd-abcdefghijkl"
}

Take note of the name, password, and tenant as these values will be used later for <spAppURl>, <spPassword>, and <tenant> respectively.

Obtain the following Parameters:

Parameter Description
spAppUrl The Service Principal app URL Required
spPassword The Password for the Service Principal Required
tenantId The tenant id for the Service Principal Required
subscriptionId The azure subscription id where the IoT Hub is deployed Required
iothub_name The name of the Azure IoT Hub Required
environment A value to use for the envrionment tag in the created device's devicetwin Optional

Start a container instance with:

docker run -it -d --privileged -e spAppUrl='<spAppUrl>' -e spPassword='<spPassword>' -e tenantId='<tenantId>' -e subscriptionId='<subscriptionId>' -e iothub_name='<iothub_name>' -e environment='<environment>' toolboc/azure-iot-edge-device-container

The device will automatically register itself as an Edge device within the specified IoT Hub using the hostname of the container instance.

You can use the environment tag to specify a Target Condition to apply apply an IoT Deployment definition.

Edge Deployment Configuration

Deploy multiple Edge Device Container Instances to K8s using Helm:

Create an Azure Kubernetes Service

Install helm and install tiller in your cluster

Navigate to the helm directory in this repo and execute the following:

helm install --name azure-iot-edge-device-container azure-iot-edge-device-container --set spAppUrl=<spAppUrl> --set spPassword=<spPassword> --set tenantId=<tenantId> --set subscriptionId=<subscriptionId> --set iothub_name=<iothub_name> --set environment=<environment> --set replicaCount=1

Use iotedge cli within the Edge Device Container Instance

You can use the iotedge cli within the docker container.

For example, when running a single instance in docker, you can open an interactive shell by running:

docker exec -it <containerid> bash

Then, within that interactive shell, run the following command to list the modules on your edge device, or any other iotedge command you wish:

iotedge list

To exit the interactive shell, simply run the following within the interactive shell:

exit

Use iotedge cli from the Host

First you need to have the Azure IoT Edge Runtime Installed on your host machine.
Find the container id for the Edge Device Container Instance by running the following command to obtain the CONTAINER ID value for the azure-iot-edge-device-container.

docker container list

Next, you need to inspect the Edge Device Container Instance using the following command on the host machine:

docker inspect <containerid>

In the output look for the IPAddress value:

IPAddress

Then, using that IP address you can run the following from the host machine:

docker exec <containerid> iotedge -H http://<IPAddress>:15580 list

For example, if the container id for your Edge Device Container Instance started with 0a and the IPAddress value for your container was 172.17.0.2 you could run:

docker exec 0a iotedge -H http://172.17.0.2:15580 list

iotedge list

azure-iot-edge-device-container's People

Contributors

azureadvocatebit avatar bretstateham avatar toolboc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-iot-edge-device-container's Issues

EdgeHub won't start due to an API version error

When trying to run stuff in the container, EdgeHub fails with the following error:

`Unhandled exception. System.AggregateException: One or more errors occurred. (Error calling CreateServerCertificateAsync: Invalid or missing API version)
 ---> Microsoft.Azure.Devices.Edge.Util.Edged.WorkloadCommunicationException- Message:Error calling CreateServerCertificateAsync: Invalid or missing API version, StatusCode:400, at:   at Microsoft.Azure.Devices.Edge.Util.Edged.Version_2019_01_30.WorkloadClient.HandleException(Exception ex, String operation) in /home/vsts/work/1/s/edge-util/src/Microsoft.Azure.Devices.Edge.Util/edged/version_2019_01_30/WorkloadClient.cs:line 109
   at Microsoft.Azure.Devices.Edge.Util.Edged.WorkloadClientVersioned.Execute[T](Func`1 func, String operation) in /home/vsts/work/1/s/edge-util/src/Microsoft.Azure.Devices.Edge.Util/edged/WorkloadClientVersioned.cs:line 77
   at Microsoft.Azure.Devices.Edge.Util.Edged.Version_2019_01_30.WorkloadClient.CreateServerCertificateAsync(String hostname, DateTime expiration) in /home/vsts/work/1/s/edge-util/src/Microsoft.Azure.Devices.Edge.Util/edged/version_2019_01_30/WorkloadClient.cs:line 35
   at Microsoft.Azure.Devices.Edge.Util.CertificateHelper.GetServerCertificatesFromEdgelet(Uri workloadUri, String workloadApiVersion, String workloadClientApiVersion, String moduleId, String moduleGenerationId, String edgeHubHostname, DateTime expiration) in /home/vsts/work/1/s/edge-util/src/Microsoft.Azure.Devices.Edge.Util/CertificateHelper.cs:line 255
   at Microsoft.Azure.Devices.Edge.Hub.Service.EdgeHubCertificates.LoadAsync(IConfigurationRoot configuration, ILogger logger) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Service/EdgeHubCertificates.cs:line 54
   at Microsoft.Azure.Devices.Edge.Hub.Service.Program.MainAsync(IConfigurationRoot configuration) in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Service/Program.cs:line 54
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at System.Threading.Tasks.Task`1.get_Result()
   at Microsoft.Azure.Devices.Edge.Hub.Service.Program.Main() in /home/vsts/work/1/s/edge-hub/src/Microsoft.Azure.Devices.Edge.Hub.Service/Program.cs:line 33`

It seems that iotedge version is really old

>iotedge version
iotedge 1.0.0 (52ef77db24126bf473265fc09c53d35290a2dd6b)

Latest release is 1.0.10.3.

Unclear container error log

When we have started container with wrong connections string by mistake, the container error log did not provided clear error description and we have spent quite a long time trying to diagnose what is the source of error.

We've started IoT Edge container with following command docker run -it -d --privileged -e connectionString='<IoTHubDeviceConnectionString>' toolboc/azure-iot-edge-device-container

Docker logs showed following errors:
[INFO] - Starting Azure IoT Edge Security Daemon
[INFO] - Version - 1.0.0 (52ef77db24126bf473265fc09c53d35290a2dd6b)
[INFO] - Using config file: /etc/iotedge/config.yaml
[INFO] - Using runtime network id azure-iot-edge
[INFO] - Initializing the module runtime...
[INFO] - Finished initializing the module runtime.
[INFO] - Configuring /var/lib/iotedge as the home directory.
[INFO] - Configuring certificates...
[INFO] - Transparent gateway certificates not found, operating in quick start mode...
[INFO] - Finished configuring certificates.
[INFO] - Initializing hsm...
[ERR!] (/home/vsts/work/1/s/edgelet/hsm-sys/azure-iot-hsm-c/src/edge_hsm_client_store.c:edge_hsm_client_store_create_pki_cert:2541) Generating certificate and key for alias iotedged-workload-ca
[INFO] - Finished initializing hsm.
[INFO] - Detecting if configuration file has changed...
[INFO] - Change to configuration file detected.
[INFO] - Removing all modules...
[INFO] - Finished removing modules.
[INFO] - Provisioning edge device...
[ERR!] - A provisioning error occurred.
[ERR!] - caused by: Provisioning error

Edge Agent itself is capable to surface connection string problems while it outputs 401 unauthorized error. Please if possible surface this information also within toolboc/azure-iot-edge-device-container logs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.