Long Live Containerization!
Node.js runs on a dedicated HTTP server and is designed to use a single thread in one process at a time. Node.js applications are event-driven and calls are asynchronous by default. Node.js applications do not follow the traditional process of receiving a request, processing it and returning a response. Instead, Node uses an event stack to handle incoming requests, pooling requests and dispatching them one after the other without waiting for a response.
Kubernetes is an open source platform for managing Linux containers in private, public and hybrid cloud environments. Many DevOps teams use Kubernetes to manage their microservices architecture, where each microservice is encapsulated in one or more containers. Kubernetes also supports a GitOps development model in which all changes to a Kubernetes cluster are fully automated and managed in source control.
Containers and Kubernetes can be deployed on-premises and in all public clouds, making them an ideal platform for cloud-native applications that need to scale quickly and must be portable between environments.
Application developers, IT system administrators and DevOps engineers use Kubernetes to automatically deploy, scale, maintain, schedule and operate multiple application containers on a cluster of nodes. Containers run on a shared operating system but are isolated from each other.
Kubernetes makes it possible to create a cluster of hosts running Linux containers and manage large numbers of containers running on those hosts.
You can deploy any application on Kubernetes, but there are certain things you can do to adapt your applications to a containerized environment. Here is how to make a Node.js application better-suited to Kubernetes:
To deploy a Node.js application to Docker or Kubernetes, you first need to build a container image. To do this, you usually start with an existing image and add additional layers of functionality as needed.
When building Node.js applications, the community provides several official Docker images to help you get started. These images provide Node.js binaries on top of an existing Linux distribution (typically Debian or Alpine). You can start from these official images and add your application as an additional layer.
There are three types of official Node.js images:
Starting from your base image, you will use a Dockerfile to build a custom image containing your application. The following is the simplest possible Dockerfile, which copies your Node.js application (app.js) into an official Node.js container image.
FROM node : 12.13.1
COPY app.js .
CMD node app.js
To build an image from the Dockerfile, place the file in the directory containing your application code and run the following command:
docker build -t myImage:new
This will create a Docker image named
myImage with the label
new based on the contents of the current directory.
To make this image usable by Kubernetes, you need to publish it to the registry. You can then run and test your application in Docker or Kubernetes.
The typical way to deploy an application to Kubernetes is via a Deployment object. Here is an example of a Deployment object that deploys two replicas of the container image we defined previously:
myImage with the label
Once this YAML is in place, you can run this command to create the Deployment in your Kubernetes cluster:
kubectl apply -f deployment.yaml
The last step is to allow other components and users to access your application. To this end, you will need to define two more Kubernetes objects: A Service and an Ingress. These are outside the scope of this article, but you can learn more about them in the Kubernetes documentation.
You deploy the Service and Ingress using these commands:
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
Once you understand the basics of Kubernetes deployment, a more convenient way to package and deploy your application is by using Helm charts. Helm is a Kubernetes package manager, and a Helm chart is a template that includes all the components we saw above: A Deployment, Service and Ingress, and ensures they are deployed correctly in one step.
In this article, I explained the basics of Kubernetes and showed basic requirements for deploying Node.js web applications to a Kubernetes cluster. I showed how to deploy your first Node.js application to Kubernetes in six steps:
I hope this will be useful as you learn to deploy your Node.js projects to a modern cloud-native environment.
Gilad David Maayan is a technology writer who has worked with over 150 technology companies including SAP, Samsung NEXT, NetApp and Imperva, producing technical and thought leadership content that elucidates technical solutions for developers and IT leadership.
Gilad David Mayaan has 6 posts and counting. See all posts by Gilad David Mayaan
document.getElementById( “ak_js_1” ).setAttribute( “value”, ( new Date() ).getTime() );
Kubernetes is hard, and it can be easy for imposter syndrome to show up when trying to figure out how all the different pieces fit together and interact. This happens over and over again at organizations at all stages of maturity. This talk covers common patterns and mistakes from the perspective of a Kubernetes certified […] The post Common Kubernetes Challenges Solved appeared first on DevOps.com. […]
The future is DAO: The distributed autonomous organization. But if we expect our leaders to become transformational and distribute their authority to autonomous teams, we have to give them effective oversight. This means we need to make our work visible and show progress in DevOps evolution as organizations digitally transform. The post How to Monitor Your Business’s DevOps Vital Signs appeared first on DevOps.com. […]
GitOps expands the use of DevOps best practices across the entire Kubernetes application life cycle, including deployment development/testing, infrastructure configuration and lifecycle management and resiliency. To enable this, administrators can configure and manage Red Hat OpenShift GitOps through ArgoCD. But regardless of whether your OpenShift clusters are hosted on-premises or in the cloud, unexpected downtime […] The post A Framework for GitOps App Recoverability With Red Hat OpenShift and TrilioVault appeared first on DevOps.com. […]
Join Avraham Shulman as he provides a security overview of serverless applications as well as insights into what is unique about serverless and the attack vectors this architecture type leaves exposed. Then, he will discuss how to secure serverless workloads across the full development life cycle. The post When Less Is More: Full Life Cycle Serverless Security appeared first on DevOps.com. […]
In this webinar, we will examine how to reduce cloud security risk and eliminate existing complexity in the cloud, by using smarter unification tools that can help security professionals reduce risk in the cloud and DevOps teams to remain empowered and agile. The post Beyond Unification: How CNAP Should Reduce Cloud Security Risk appeared first on DevOps.com. […]
Join the CISO Talk Master Class live conversation. Part 6 brings all the elements into a cohesive, integrated strategy: continuous security strategy, leveraging frameworks, effective response strategies, growing next-gen security experts and communications that win and combat confusion. Join hosts Mitch Ashley and Mat Newfield and an elite panel of cybersecurity experts as they bring.. The post CISO Talk Master Class Episode: Catch Lightning in a Bottle – The Essentials: Bringing It All Together appeared first on Security Boulevard. […]
Even if you have a secure, compliant, correctly configured and continuously monitored cloud infrastructure, there are still major risks associated with your cloud-deployed apps. Secure cloud infrastructure does not mean secure applications, and solutions like cloud security posture management (CSPM) do not go deep enough into the application layer to ensure you are secure. There.. The post Why Cloud-Native Applications and APIs Are at Risk appeared first on Security Boulevard. […]
DevOps has been around for more than a decade. However, security teams still struggle to react to the drastic changes it brought to the SDLC. The influx of tooling needed to facilitate DevOps also brought with it added attack surface, complexity and a lack of visibility; all of which have left security teams on their.. The post Top 5 Reasons Why Effective SDLC Security Controls Are So Difficult appeared first on Security Boulevard. […]
Join Avraham Shulman as he provides a security overview of serverless applications as well as insights into what is unique about serverless and the attack vectors this architecture type leaves exposed. Then, he will discuss how to secure serverless workloads across the full development life cycle. The post When Less Is More: Full Life Cycle Serverless Security appeared first on Security Boulevard. […]
In this webinar, we will examine how to reduce cloud security risk and eliminate existing complexity in the cloud, by using smarter unification tools that can help security professionals reduce risk in the cloud and DevOps teams to remain empowered and agile. The post Beyond Unification: How CNAP Should Reduce Cloud Security Risk appeared first on Security Boulevard. […]
Long Live Containerization!