HTTP Endpoint routing using Node-RED as a service in Kubernetes

10/1/2018

I would like to run Node-RED as a service on Kubernetes to be able to build a custom API using the HTTP IN nodes. The goal is to be able to push any number of different flows to an arbitrary container running Node-RED using the Node-RED API.

I have tried running Node-RED as a service with 5 replicas and built a flow through the UI that has an HTTP in and HTTP out node. When I try hitting the service using curl on the minikube ip (e.g. curl http://192.168.64.2:30001/test), it will only return the results if the load balancer happens to land on the container that has the flow. Otherwise, it will return an error with HTML.

Any advice on how I should go about solving this issue? Thanks!

-- kturcios
docker
http
kubernetes
load-balancing
node-red

1 Answer

10/1/2018

This is working as expected. If you are interacting with the Node-RED editor via the load balancer you are only editing the flow on that instance.

If you have 5 instances of Node-RED and only one of them is running a flow with the HTTP endpoints defined then calls to that endpoint will only succeed 1 time in 5.

You need to make sure that all instances have the same endpoints defined in their flows.

There are several ways you can do this, some examples would be:

  • Use the Node-RED Admin API to push the flows to each of the Node-RED instances in turn. You will probably need to do this via the private IP Address of each instance to prevent the load balancer getting in the way.
  • Use a custom Storage plugin to store the flow in a database and have all the Node-RED instances load the same flow. You would need to restart the instances to force the flow to be reloaded should you change it.
-- hardillb
Source: StackOverflow