Deploy your Node Red Environment onto Kubernetes Clusters using Google Cloud Platform
Node Red gives the ability to write code very quickly and deploy it quickly as well. The main issue that arise when using Node Red is the scalability. In this story, I will be going over how to deploy your Node Red code on Kubernetes Cluster on Google Cloud Platform.
In this tutorial, we will create a Node Red Docker Image and then upload the image to Docker Hub or Google Cloud Platform Container Registry. Then we will create a Kubernetes environment and pull the newly image that we built and start our Docker Container and create multiple pods to scale our Node Red App.
- Make sure you have Docker install
- Setup your Google Cloud Platform account
- Follow the QuickStart for Mac OS for Google Cloud Platform: https://cloud.google.com/sdk/docs/quickstart-mac-os-x
- Just follow up to gcloud init
- Run the command
docker run -it -p 1880:1880 --name mynodered nodered/node-red-docker
For more information about this command, go to https://hub.docker.com/r/nodered/node-red-docker/
2. If you open localhost :1880 you will be in the Node Red console. If you want to install other nodes you can run
docker exec -it mynodered /bin/bash
3. Now your running the command line in your container, you can now run npm install the packages you want to run.
npm install node-red-node-watson
Then once you install all the packages you want to use, run the command, this will restart the container
docker stop mynodered docker start mynodered
4. Once you have your flow setup up, run the command
//This command will create a new image from the container docker commit mynodered custom-image-name
5. You can run your new image to make sure the changes has made it onto the new images by the command
docker run -d --restart=always -p 1880:1880 customer-image-name:version
6. Once your happy with the docker image you want to push your image into a registry, either docker.hub or google cloud platform registry
//Google Container Registry Push Image https://cloud.google.com/container-registry/docs/pushing-and-pullingdocker tag customer-image-name gcr.io/[project-id]/customer-image-namegcloud docker -- push gcr.io/[project-id]/customer-image-name//Docker Hub Push Image https://docs.docker.com/datacenter/dtr/2.4/guides/user/manage-images/pull-and-push-images/docker tag [image id] your-hub-user-name/customer-image-name docker push your-hub-user-name/customer-image-name
7. Go to your google cloud platform and choose a project.
8. Next go to to Kubernetes Engine and click on create cluster and fill in the needed information, i.e. Name, Description, Zone, Size and then click on Create.
9. Once your cluster is created, click on Connect and copy under the text : “Configure kubectl command line access by running the following command”. Next open the Google Cloud Shell and paste the command.
10. Now you are connected with your cluster, now we want to pull our image and start running our image as a container.
//Google Cloud Platform Pull Image from Registry kubectl run customName --replicas=4 --image=gcr.io/[project-id]/custom-image-name --port=1880//Docker Hub Pull Image from Registry kubectl run customName --replicas=4 --image=your-hub-user-name/customer-image-name --port=1880--replicas 4 //this command will created the numbers of pods you want, in this case your are creating 4 pods --image=gcr.io/[project-id]/custom-image-name //This command is referring to which image you want to pull --port=1880 //This command refers to which port your want your docker container to run on, in this case port 1880
11. Next we want to expose our application to the world to use, so run the command
kubectl expose deployment/projectName --type="LoadBalancer"
12. Now docker container is running on cluster and expose to the outside. To see the IP address which is running, run the command
kubectl get services
Now you can log into your Node-Red instance by: EXTERNAL-IP:1880. If you want to update your Node-Red, you need to update your image and then have your cluster point to the new image.