Logo Dave LobosDave Lobos About
Cover Image: Setting Up a Local Development Stack with Minikube, NodeJS, and Nginx

Setting Up a Local Development Stack with Minikube, NodeJS, and Nginx

This guide aims to walk you through setting up a containerized local development environment with hot-reloading using Minikube, Skaffold, NodeJS for server-side logic, and Nginx as a reverse proxy and static files server.

You can find the code for this project on GitHub: https://github.com/DaveLobos/node-nginx-app

Using Nginx as a reverse proxy for a NodeJS application is quite common, this projects serves as a quickstart template for you to use on your own projects which you can later deploy to AWS Fargate, Google Cloud Run etc...

Skaffold provides us with hot-reloading for our local environment, every time you make changes to your NodeJS code or static assets on Nginx, containers will be re-built and re-deployed to the local Minikube cluster automatically, speeding up development.

Getting started

The following tools must be installed on your computer:

clone the repository

$ git clone https://github.com/DaveLobos/node-nginx-app.git

a new directory named node-nginx-app will be created, navigate to it

$ cd node-nginx-app

start Minikube

$ minikube start

run Skaffold, this will build the NodeJS and Nginx containers and deploy them to the Minikube cluster.

$ skaffold dev

expose port 8080 of the application

$ kubectl expose deployment app --type=LoadBalancer --port=8080 --name node-nginx-app

after exposing it, port 8080 will be mapped to a different port number which can be accessed from your computer, check what port that is

$ kubectl get services

NAME             TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE

node-nginx-app   LoadBalancer   10.101.66.7     <pending>     8080:30686/TCP   5s

you also need to check the ip address of the minikube cluster

$ minikube ip
192.168.49.2

Now that you know the ip address of your Minikube cluster and the service port, you can access the application from your browser or terminal.

$ curl -ik http://192.168.49.2:30686/
192.168.49.2

Understanding the Application Structure

.
├── deployment.yaml
├── README.md
├── skaffold.yaml
├── bash
│   ├── expose.sh
├── nginx
│   ├── Dockerfile
│   ├── default.conf
│   └── static
│       └── styles.css
└── node
    ├── Dockerfile
    └── app
        └── main.js

The application is comprised of several directories and files, next up is an explanation of the most important ones.

Deployment and Skaffold configuration files

The "deployment.yaml" file dictates how the application will run within the Kubernetes cluster. It specifies the two containers that make our deployment.

The "skaffold.yaml" file configures Skaffold for automated deployments.

Nginx configuration

The "nginx/default.conf" file configures Nginx to do the following:

NodeJS application

The "node/app/main.js" file is the entrypoint of the NodeJS application, it simply responds to all requests with a "hello world" page.

This setup offers a foundation for local development, you can use it to build more complex web applications or microservices.