Video Link HERE
Vagrant Intro HERE
Ansible Intro HERE
Nodejs+Nginx Intro HERE
- Load balancing using nginx
- Launching VMs using vagrant
- Configuring the VMs using ansible
- Ansible Roles
- Templates
- Variables
- Handlers
- Simple shell script for manual deployment
+----------+
| Nginx |
| proxy |
+----+-----+
|
| Load Balancing
+------+-------+
| |
+----v----+ +----v----+
| NodeJS | | NodeJS |
| VM 1 | | VM 2 |
+---------+ +---------+
- Load balancer
- Caching (Future)
- SSL Termination (Future)
- Advanced rules (Future)
- Lets us run multiple instances of our app
- Which gives redundancy and fault tolerance.
- Let's us deploy without causing downtime (We can update the backends one at a time)
That is only for the purpose of this demonstration. It does not make sense to have two VMs running just one process each. But I wanted to show the concept of loadbalancing
We have three VMs to launch, obiously we will use Vagrant for that.
Vagrant files HERE
Ansible files HERE
We will have these roles
- common : This contains common stuff for all the servers (git, vim etc)
- nginx-common: Whatever that is common for all nginx servers (like, installing nginx itself)
- nginx-nodejsapp: nginx stuff specific to our nodejsapp
- nodejs-common: Common for all nodejs apps
We need - Nginx installed - Nginx virtualhost configuration
We need - NodeJS installed
Of course we need a demo app. This time, we will use an express based simple
hello world application. Why express? Because I want to introduce npm install
as part of our deployment.
The sample app is HERE
The package.json
was created using the following. I am leaving it here
for reference, you don't have to do this as the package.json
is already
present
# Just press Enter for all the prompts
npm init
And then
npm install express --save
Which will save the dependency (express) into the package.json
We shall have a simple, dumb script that will do the deployment for us
- Clone the codebase
- Run
npm install
- Copy the resulting everything into the nodejs machines
- Restart the node processes
The dumb script is present HERE Please don't use this deploy script for anything other than learning