
Setting Up a Local Development Stack with Minikube, NodeJS, and Nginx
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:
- Docker
- Minikube
- Skaffold
clone the repository
a new directory named node-nginx-app will be created, navigate to it
start Minikube
run Skaffold, this will build the NodeJS and Nginx containers and deploy them to the Minikube cluster.
expose port 8080 of the application
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
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
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.
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:
- listen to upcoming requests on port 8080
- serves static content to requests with a url that starts with /static
- routes any other requests to the NodeJS application
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.