Deploying web app in AWS using Salt stack

Introduction:

This document is about deploying a Java, NodeJS web app in AWS using Saltstack and creating infrastructure using Terraform

Prerequisites:

  • Knowledge of AWS
  • Knowledge Saltstack
  • Linux
  • Terraform

Saltstack:

Saltstack is a configuration management tools which supports both push based and pull based management. Salt-master, salt-minion are the terms which describes server and client in pull based configuration of Saltstack

Terraform:

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Description of Web app

The web app is consisting of two application services

Java: is the backend for the web app

NodeJS: is the front-end UI for the web app

Steps:

  • Configure the terraform with AWS provider for the IAM user in AWS account
  • To Generating access and secret keys in IAM console follow the steps
  • After generating keys create a provider.tf file with following contents

sa1

  • Replace the region if you want to change
  • Create a instance.tf file which used to create salt-master in AWS

sa2.JPG

sa3.JPG

  • Now we are creating a salt master with static private IP in default VPC, subnet
  • Create route53.tf file to create a private hosted in AWS to boot salt-minion with master using custom domain name

sa4.JPG

  • In this file we are creating a private hosted zone, creating a record set as sms-api.salt.com and linking it our master private IP
  • Use Terraform plan command to evaluate code for any syntax errors
  • Use terraform apply command to create the infrastructure
  • Log in to the AWS console and navigate region that have update observe the changes
  • Using user data field in the instance.tf we have passed a startup script to install salt-master in AWS
  • Contents of the script

sa5.JPG

sa6.JPG

  • We are install another component salt-cloud which used to maintain, configure infrastructure in cloud providers like AWS
  • Salt-cloud user /etc/salt/cloud.providers. d/ uses this location for cloud provider credentials
  • Define a file with. conf extension to configure. Sample file looks like this aws_ap-northeast-1. conf

sa7.JPG

 

  • This file defines instance role and credentials
  • Salt-master needs ec2 full access role or administrator role

Salt-cloud uses /etc/salt/cloud.profiles. d/ location for instances configuration

Example

sa8.JPG

s9.JPG

  • Here defining two instances for two instances one for java backend and other for NodeJS frontend
  • Salt-cloud uses /etc/salt/cloud.maps.d. d/ location for mapping cloud. Profiles to cloud providers

Example test. conf

s10.JPG

  • Now run salt-cloud -m /etc/salt/cloud.maps.d/test.conf and enter
  • Now salt-cloud in salt-master will create two instances, installs salt-minion and bootstraps with salt master runs the startup script defined /etc/salt/cloud.profiles.d/test_env.conf for those instances
  • Now we have to install Java, MySQL in java backend, NodeJS in frontend
  • We are writing top.sls to installed these packages in respective instances

Top.sls

s11.JPG

Defining api-java.sls

s12.JPG

Defining nodejs.sls

s13.JPG

As instances some initial steps we are passing startup scripts through salt

Script for java backend

s16.JPG

Now run salt salt ‘*’ state.apply

TO apply changes enter public ip in your to check UI

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s