Home/Node.js/Getting started with Node.js applications on Microsoft’s Azure Kubernetes Service (AKS)
About Azure Kubernetes Service (AKS)
AKS is Microsoft’s managed container environment hosted on Azure. Using Kubernetes, AKS gives you the power of orchestration for your applications with provisioning, upgrading and scaling. All of this without initial setup or ongoing maintenance.
Kubernetes is an open-source system for automating deployment, scaling and management of containerised applications.
You may be asking why it’s important to understand this infrastructure. With a lot of infrastructure moving towards containerised solutions it’s worth understanding, as a Node.js developer, how your applications run in a production environment.
Being able to replicate a production setup on your local machine can make debugging issues quicker and easier.
Understanding the build process once you’re ready to ship code can help avoid situations where developers don’t understand how applications are built and run in production.
Shared knowledge can help contribute towards a collaborative environment between development and operations teams.
This post steps you through deploying a Node.js application to AKS using Helm; beginning with replicating the setup locally and then transferring over to a hosted, production-ready environment.
Helm makes managing Kubernetes applications easier via customisable Charts which define application setup, provide repeatable installations and serve as a single point of authority.
Before diving into the Azure setup, let’s replicate the production setup locally. This provides you with a playground to test changes without the need to push to a hosted environment.
NearForm provides images via the Docker Hub for Node.js 8 LTS, 9 and 10. These images are updated within a very short time of any Node.js release or OS base image change. Commercial support is available for 8 LTS.There are images for CentOS, Red Hat Enterprise Linux and Alpine Linux.The Dockerfile being used is available at ./infrastructure/docker/app.Dockerfile, it uses NearForm’s Node.js Alpine image.
# Create app directory
COPY package*.json ./
RUN yarn install --production=false
COPY . .
RUN yarn run build
CMD [ "yarn", "start" ]
Generally, you tag images with a specific version number but for local development, this is not necessary. Using the latest version allows you to run the same build command each time you need to rebuild the image.
Once built see the image listed by running the command docker images.
Install Your Application Stack
To build your Kubernetes deployment, service and ingress run the following command:
As suggested by the output of the above command you can run:
kubectl --namespace default get services -o wide -w nginx-controller-nginx-ingress-controller
This command waits for the pending IP address to be created and notifies you when its done.
Once you have the external IP address, requesting it returns the default 404 response from NGINX.
The final step is to configure your DNS to create an A record pointing the domain name specified in your Helm chart at the external IP address provided. Once the DNS change propagates your application is running on your defined hostname.To set up HTTPS and automatic HTTP to HTTPS redirects in AKS there are detailed instructions provided by Microsoft which expand upon the NGINX ingress controller setup.
You’ve taken a Node.js application and deployed it to a modern infrastructure while avoiding some of the setup and maintenance costs associated with building a production ready, scalable, containerised solution.
The declarative nature of much of this setup lends itself well to automation. The next steps are to automate the process of upgrading applications via CI as well as scripting the initial setup to be replicable for any application.
Don’t miss a beat
Get all the latest NearForm news,
from technology to design.