VOOZH about

URL: https://thenewstack.io/tutorial-kubernetes-for-orchestrating-iot-edge-deployments/

⇱ Tutorial: Kubernetes for Orchestrating IoT Edge Deployments - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2018-10-02 03:00:50
Tutorial: Kubernetes for Orchestrating IoT Edge Deployments
tutorial,
Kubernetes

Tutorial: Kubernetes for Orchestrating IoT Edge Deployments

As Kubernetes transforms into a universal scheduler, it’s capabilities are exploited to orchestrate deployments across a diverse set of workloads.Microsoft’s Virtual Kubelet project takes advantage of the extensibility features of Kubernetes to orchestrate deployments targeting external environments.
Oct 2nd, 2018 3:00am by Janakiram MSV
👁 Featued image for: Tutorial: Kubernetes for Orchestrating IoT Edge Deployments
Feature image via Pixabay.

As Kubernetes transforms into a universal scheduler, its capabilities are exploited to orchestrate deployments across a diverse set of workloads. From virtual machines to containers to edge computing modules, Kubernetes is becoming the preferred platform for managing deployments at scale.

Microsoft’s Virtual Kubelet project takes advantage of the extensibility features of Kubernetes to orchestrate deployments targeting external environments. Virtual Kubelet acts as a bridge between the Kubernetes control plane and a 3rd party resource scheduler. In its current form, it works with Microsoft’s serverless container platform, Azure Container Instances, Azure IoT Edge, and even AWS Fargate. Given the power and simplicity of Virtual Kubelet, we can expect to see other integrations with it.

The most interesting integration of Virtual Kubelet is with Azure IoT Edge where Kubernetes talks to Azure IoT Hub to deploy containers in remote edge devices. The advantage of this integration is the ability to use standard Kubernetes tools and deployment mechanism to orchestrate edge modules at scale.

It makes complete sense to use Kubernetes for orchestrating edge computing modules. Azure IoT Edge heavily relies on a container runtime and containers to perform local processing. Each IoT Edge device may run dozens of containers that work in tandem to handle data processing and business logic. These containers are pushed through an IoT Hub where multiple edge devices are registered. By using tags, containers may be deployed to more than one edge device at a time.

👁 Image

If we observe closely, Azure IoT Hub acts like a typical worker node of Kubernetes. Once Azure IoT control plane instructs to run an IoT edge module as a container on the target device, it packages the container image as a module and hands it over to the remote edge device. Since each edge device may run more than one container, they may be compared to Kubernetes pods.

When an IoT Hub is registered with Kubernetes through Virtual Kubelet, the master nodes will treat IoT Hub as a node. When a deployment is targeted at IoT Hub, Kubernetes control plane simply hands over the scheduling part to IoT Hub. Developers and operators can use familiar manifests declared in YAML that is pushed through the kubectl CLI.

In this tutorial, we are going to extend the Azure IoT use case discussed in the last part to Kubernetes. We will perform blue/green deployments and even rollback and roll forward Azure IoT Edge modules from kubectl.

Before proceeding further, make sure you completed the previous part of the tutorial. You also need access to a Kubernetes cluster. You may use Minikube on your local development machine. Install and test Helm as we will deploy Virtual Kubelet as a chart.

Let’s start by cloning the Virtual Kubelet repo from Github.

$ git clone https://github.com/Azure/iot-edge-virtual-kubelet-provider.git

Grab the Azure IoT Hub owner connection string from the portal to create a secret in Kubernetes. You may also run the below command to get the connection string.

$ az iot hub show-connection-string --resource-group TNSIoT --hub-name TNSIoTHub

$ kubectl create secret generic my-secrets --from-literal=hub0-cs=’HostName=TNSIoTHub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=oNVfrvc1bsfmrXaofsVQAhvq74xQ/rHiRzClqPOsFgc=’

Install Virtual Kubelet Helm Chart in the Kubernetes cluster. Make sure you set the RBAC flag to true.

$ cd iot-edge-virtual-kubelet-provider/

$ helm install -n hub0 --set rbac.install=true src/charts/iot-edge-connector

👁 Image

Verify that IoT Hub is showing up as a node in our Kubernetes cluster.

👁 Image

We are now ready to deploy an IoT edge module from kubectl. Before that, let’s create the YAML file with the deployment manifest.

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: matrix
spec:
  selector:
    matchLabels:
      app: matrix
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 0%
      maxUnavailable: 100%
  template:
    metadata:
      labels:
        app: matrix
      annotations:
        isEdgeDeployment: "true"
        targetCondition: "tags.type='bulb'"
        priority: "150"
        loggingOptions: ""
    spec:

affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - matrix
            topologyKey: "kubernetes.io/hostname"

      containers:
      - name: matrix
        image: "janakiramm/matrix:v1"
      nodeSelector:
        type: virtual-kubelet

      tolerations:
      - key: azure.com/iotedge
        effect: NoSchedule

---

kind: ConfigMap
apiVersion: v1
metadata:
  name: matrix

data:
  status: running
  restartPolicy: always
  version: "1.0"
  createOptions: |
    {
      "HostConfig": {
        "Privileged": true,
        "network" : "host"
      }     
    }

The above file contains the definition of a standard Kubernetes deployment and a config map. The deployment has a few annotations that are forwarded to IoT Hub by the Virtual Kubelet.
👁 Image

The target condition matches the tags defined in the digital twin of the edge device. If you recall, in the previous tutorial, we added a couple of tags to our device with the below command.

$ az iot hub device-twin update --device-id Pi1 --hub-name TNSIoTHub --set tags='{"device":"pi1","type":"bulb"}'

👁 Image

When Kubernetes pushes the deployment through IoT Hub, the control plane will apply the configuration to all the devices with matching tags.

The config map is used to set the module configuration which is used by Azure IoT Edge runtime when creating the containers. In our case, we need to run the container in a privileged mode which is defined in the config map.

We can now create this deployment through kubectl CLI. Notice that we are adding the –record flag to enable rollback and roll forward of deployments.

$ kubectl apply -f matrix.yaml --record

Check that the pod is created.

Since the image, janakiramm/matrix:v1, turns the matrix to blue, your Raspberry Pi should light up with all blue LEDs.

Visiting the Azure Portal’s IoT Edge Deployment Section confirms that the module is deployed on the device that matches the tag type=’bulb’.

Now, let’s use the Kubernetes way of updating the image to V2. We can directly update the image defined in the deployment with the below command. We are recording this change as well.

$ kubectl set image deployment/matrix matrix=janakiramm/matrix:v2 --record

The second version of the image sets the color of the LED matrix to green. You should be able to see that change in just a few seconds.

Since we are using Kubernetes deployments, we can perform PaaS-style operations on the modules.

The command, kubectl rollout history will show all the changes made to the deployment.

👁 Image

Let’s rollback to the very first step in the history. This should take us back to the previous version of the module which will change the color of the LED matrix to blue.

$ kubectl rollout undo deployment/matrix --to-revision=1

All the deployment changes initiated from Kubernetes are recorded in the Azure IoT Edge Deployment history.

👁 Image

Congratulations! You just did a blue/green (literally) deployment on the edge device!  Once a set of devices are tested with a specific version of a module, they can be rolled out to all other devices.

This scenario is just one of the examples of Kubernetes extensibility. We can expect to see many workloads moving to Kubernetes for advanced scheduling capabilities.

TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.