Published on

Deploy Node-RED flows to the Cloud (Azure)

Authors

In this tutorial, we will deploy Node-RED flows we've created before to the cloud using Microsoft Azure. By hosting our Node-RED flows in the cloud, we can control remotely and access the data from anywhere. This guide will take you step-by-step through the process of deploying your Node-RED flows to Azure, and provide you with the knowledge and skills to start building your own cloud-based IoT solutions.

Prerequisites

  • SSH Client - Eg: PuTTY
  • Microsoft Azure account
tip

If possible, register to the Azure account as student to claim the free $100 credit.

Create a new Virtual Machine (VM) instances

Virtual machine is basically a computer that lives in Azure infrastructure. Open Azure portal and click on Virtual Machine.

Azure Virtual Machine selector

Click on Create > Azure virtual machine on the dropdown menu.

Create Azure VM

In the Create a virtual machine form, fill in the particulars. Below are some important info you need to fill.

ItemDescription
Resource groupCreate new or select existing resources
Virtual machine nameGive any name. Eg: my-node-red-vm
ImageUbuntu Server 20.04 LTS (Ubuntu 18.04 will cause some issue when installing node) Select Ubuntu Server 20.04
SizeThe docs suggest A1 Basic, but I couldn't find it. So, I'll go with Standard_B1s. Keep in mind that Node.js operates on a single thread, so having multiple cores in a Node-RED instance will not bring any advantage. Azure VM Sizes and pricing
Administrator accountYou can leave it as default Azure Administrator account
Inbound port rulesLeave it as default Azure Inbound Rules

Next, go to the Networking tab.

Networking tab

in the NIC network security group, change the option from Basic to Advanced. Then, in the Configure network security group, click on Create new.

NIC Advanced option

Click on + Add an inbound rule. Set the value as follows:

ItemValues
Destination port ranges1880
ProtocolTCP
Priority1010
NameAny name. Eg: node-red-editor

Click Add. You should see your new rule is added to the Inbound rules. Click on OK.

Then, click on Review + create to finalize your VM creation.

Azure review

In will take a moment to validate the information. Once it's done, click on Create. A dialog Generate new key pair should pop out to let you download your private key. Go ahead and click on the Download private key and create resources.

Azure download key pair

A .pem file will be downloaded, and Azure deployment worker will start kicked in to start your VM deployment. You can see the progress from the notification panel. Once it's done, click on Go to resource to view your freshly created VM.

Then, go to Connect, copy the <username>@<public ip address> from the example command. For example, mine is azureuser@20.115.54.38.

Azure VM Connect SSH

Accessing your VM's Shell

Key conversion

note

As soon I finish writing this tutorial, I realized that you can connect to the VM's shell by just using PowerShell on Windows (on Linux/MacOS, I know they have CLI ssh). Demo video here.

We'll be using PuTTY go access your VM. But, first, we are first going to convert the downloaded .pem file into something that PuTTY can understand. Open PuTTYgen to get started.

PuTTY gen

In the PuTTYgen window, click on Conversion > Import key. Import the .pem file we've downloaded from the Azure portal before. PuTTYgen should be able to read it.

Then, click Save private key.

Putty save private key

A warning dialog may appear, just click Yes to proceed. Save it anywhere on your computer. Note that the converted file will be saved as .ppk.

You can now close PuTTYgen.

Establishing connection

Now, open the main PuTTY app. Click on Connection > SSH > Auth > Credentials.

In the Private key file for authentication, browse the generated .ppk file we've generated before.

PuTTY SSH auth
note

It is also possible to generate the key pair using PuTTY, and then give your public key to the VM. Read more here.

Go back to Session, in the Host name textbox, paste the <username>@<public ip address> that we've copied from Azure portal before. Leave other settings as default and click on Open.

Putty init session

A warning dialog might be appeared, click on Accept to proceed.

tip

You may wanted to save the PuTTY session, so next time you want to access the Shell, just load the session from disk

PuTTY will connect you to the Azure VM. Within a few seconds, BOOM! 💥. We've gain access to our VM's Shell. Congratulations, you are now a hacker.

You can verify by typing command uname -a to get the OS information.

putty Uname Azure

Install Node-RED

First, install the recommended version of Node to the machine.

curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs build-essential

Then, install Node-RED

sudo npm install -g --unsafe-perm node-red

Open Node-RED

Now, Node-RED is ready to be started. Run:

node-red
Node RED started

After it has been started, open your browser and go to <public ip address>:1880. For example, mine is 20.115.54.38:1880.

tip

You can find your public IP address from the Azure Portal (in here) or using command like here

With that, you now have the Node-RED running on your Azure cloud infrastructure 🎉.

NodeRED on cloud Azure

At this point, you already can start to design your flows and can deploy instantly at the cloud. But, if you already have developed a flows before this locally, why not just importing the flows to the Azure VM? Continue reading...

Import existing flows to Node-RED

Before we proceed, let's define:

  • Local Node-RED : Node-RED instance that we run on our local machine
  • Cloud Node-RED : Node-RED instance that we've just deployed to the Azure VM
note

The steps outlined here is similar then you wnat to transfer the Node-RED flows from one machine to another

We'll need our exported .json file first (learn how to export Node-RED flows to JSON is previous article).

Then, we'll need to list out the palettes used in the current flows because we'll need to install them. So, on the Local Node-RED > Menu > Manage Palettes. Take notes of the installed palettes. In my case, I only have one additional palettes: node-red-dashboard.

Nodered palettes installed

Now, back to Cloud Node-RED, click on Menu > Manage Palettes > Install to install all palettes you need.

Then, click on Menu > Import. You can paste the json content or import the .json file. Then, click on Import.

Nodered import json dialog

The imported flow will look the same as your local Node-RED's flow.

Imported flow

Finally, hit Deploy to save and deploy the flows.

Open the dashboard UI, connect ESP32 like we did before and the result is something similar below:

Notice that there are few milliseconds delay between ESP32 and the Node-RED dashboard. Perhaps because we are using free public mqtt broker, so the connection speed is throttled.

shameless plug

I made the Serial Monitor application that you see above. It is called SeriLink. Learn more here.

Concluding remarks

That's it. You now can continue to develop your flow on the cloud and deploy it right away so that you, or anyone can access it. The process is long, but easy to understand, right? 😉

Remember to watch out your Azure usages & quotas to avoid extra charges.

You may ask, how do I want to do similar like this using AWS? IMO, the process maybe similar here and there. Just try that out. If I have time, I want to make a YouTube tutorial InshaAllah.

References