Purpose of this post is to provide step by step process of deploying applications built in Java stack to cloud service providers (CSP).
Post is divided into two major sections viz.
Section I - Brief Introduction of Java Application to be deployed
Section II - Deploy java application to AWS cloud (PaaS solution) - Elastic Beanstalk in action
The process depicts guidelines as a PaaS solution. No IaaS is used. All Environments would be managed by CSP only as PaaS, thus no manual creation of compute services like EC2 etc.
Also focus of the post is to provide ways of deployment rather than application/service functionality.
Lastly, for all CSPs in action, free tier pricing is used, so it is advised to the audience to sleep off resources when not in use to maintain a free tier usage plan.
Java Application In Action
Microservices are a software development technique, a variant of the service-oriented architecture (SOA) structural style, that arranges an application as a collection of loosely coupled services. In a microservices architecture, services are fine-grained and the protocols are lightweight.
Application developed for deployment exercise is a Spring Boot Stack Microservice.
Microservice developed for deployment is an OTP (One Time Password) service that exposes three functionalities to its consumers
Generate OTP - http://<subdomain>. <domain>/v1/generate - Generates unique OTP (one-time password) and send OTP to user’s mobile in context as SMS. As of now SMS service is switch off as document inclination is towards deployment to cloud rather than application functionality and also it is paid service.
Verify OTP - http://<subdomain>. <domain>/v1/verify - Verifies the receives OTP by user with the service
List all OTP audit log - http://<subdomain>. <domain>/v1/getList - provides list of all OTP statuses for audit purposes. Service uses in memory database H2 to persist generated OTP.
Assumptions
Post is totally inclined towards study of PaaS, there is no UI components attached to it and only service endpoints are exposed for consuming.
For testing endpoints, Postman, a third-party tool is used to test and verify service endpoints.
For traffic generation, JMeter is used to send finite number of service requests to microservice endpoints concurrently and with elapsed time i.e. 2000 requests in 30 sec.
No actual SMS would be sent to user mobile as SMS gateway is a priced enitity.
Platform as a Service (PaaS)
Platform-as-a-service (PaaS) is a type of cloud computing offering in which a service provider delivers a platform to clients, enabling them to develop, run, and manage business applications without the need to build and maintain the infrastructure such software development processes typically require. The PaaS provider hosts everything—servers, networks, storage, operating system software, databases—at their data center; the customer uses it all for a for a monthly fee based on usage and can purchase more resources on-demand as needed. In this way, PaaS lets your development teams to build, test, deploy, maintain, update, and scale applications
Amazon Web Services (AWS)
This section describes step by step process of setting of AWS and using it for application deployment.
AWS Account Creation
1. To get started, this section describes the steps for creating AWS account. Navigate to https://aws.amazon.com/ and click on “Create a Free Account”.
2. Provide the email address and AWS account name in the form provided.
3. Provide information like type of account, geographical details and Payment Details. As we are enrolling for free tier, no payment would be deducted within standard usage. If utilization of any resource exceeds standard limit, extra utilization would be charged against payment method defined. Once information is complete, AWS would charge your payment for INR 2.00 (refundable) to verify the details. Once details are verified, you are good to go to use AWS resources.
AWS Console Login
Navigate to https://aws.amazon.com
Click on My Account AWS Management Console
3. Login with Root User. For this document, creating IAM users is out of scope, so would continue with single root user
4. Once user gets authenticated, we would be presented with AWS dashboard with list of all services(resource) we can use for our application.
Selecting AWS Region
Select (console) the desired AWS Region. We will select the region closest and would select “Asia Pacific (Mumbai) – ap-south-1. We can probably select any regions available but to reduce latency, better to be nearer.
So now we have completed initial account creation and setup. Let’s gear up for real fun with Elastic Beanstalk.
Elastic Beanstalk
AWS Elastic Beanstalk is a compute service which makes it easier for the developers to quickly deploy and manage applications which you upload to the AWS cloud. Developers simply upload their application to the AWS cloud, and then let the AWS Beanstalk provision and handle the configuration for you. Your application will be provided with capacity provisioning, load balancing, auto-scaling, and health monitoring. a developer can deploy an application without provisioning the underlying infrastructure while maintaining high availability.
Before using Amazon elastic beanstalk service, create a local application in any stack (platform). It can be Python, PHP, Node.js, etc. Once application is ready, create an application in Elastic Beanstalk with an environment where you can upload your local application. Then you deploy it and use the URL provided for it to launch it. Major benefits include: Autoscaling | Easy to Start | Cost Effective | Management/updates
Components
Application
An Elastic Beanstalk application is logically considered an equivalent to a file containing the source code. The file (application as a zip file) is the application in the Elastic Beanstalk environment.
Application Version
Upload different versions of application AWS Beanstalk.
Environment
Collection of AWS resources are an environment and an environment can only run one application version at a time.
Environment Tier
There are two environment tiers available - Web Server Environment and Worker Environment. Web Server Environment is for web applications and Worker environment is for scheduled, batched applications
Environment Configuration
The configuration of an environment is a set of parameters like security group, Instance type, and platform version. If you change the configuration, Amazon Elastic Beanstalk implements it dynamically.
Platform
A platform is a combination of all the AWS Beanstalk components, an Operating system, a programming language runtime, and a web server to run the applications.
Elastic Beanstalk Implementation
This section we would use each and every component of Elastic Beanstalk discussed in earlier section and prepare an environment (platform) to deploy application.
This section only talks about getting ready with Elastic Bean Stalk and deploy sample application provided with Elastic beanstalk. Real application would be deployed in next section. This helps in early testing of platform.
Navigate to AWS Management console and find service Elastic Beanstalk and select the service from drop down. Other way is to find manually from the list of services in management console (dashboard)
Basic Topology
Following diagram depicts the basic components in actions. Diagrams shows how the request traffic flow across different resources independent of type of stack used for application development.
Create Application
Once Elastic Beanstalk is selected, screen would navigate to Elastic Beanstalk dashboard. On dashboard right side click on “Create New Application”
2. On Create new application screen, provide application name and meta tags (addition contextual information). As we would deploy OTP microservice, application name is given as “otpService”
3. When create button is clicked, Application would be created (placeholder) and we would automatically navigate to OTP Service Application bean with Elastic Beanstalk service
Create Environment
After creating application (placeholder) in earlier section, now we need to create an ENVIORNMENT for application, thus click on “create one now” to create a new environment.
Select the type of environment. Select the Web Server Environment as we need to deploy web service. Worker environment is for batch, schedule or long running application types.
3. Provide an environment name and sub-domain of your application. This sub-domain is global sub-domain and allocated subject to availability in domain registry for ap-south-1.elasticbeanstalk.com where ap-south-1 is region selected for our account for this documentation.
4. Select the platform as “Java” from list of options available.
5. For environment, at first, we will not upload any code instead would select “Sample Application” so that we can test the accuracy of environment created. Once we are satisfied with environment configuration, we will deploy OTP Microservice.
6. Click on “Configure more options” button. This section would provide us with various configuration changes that can be done with environment including EC2 instance types, scaling, Security groups etc. For now, keep it all default.
7. Lastly click on Create Environment. environment creation would take several minutes, so relax and observe log messages/stack trace and salute the creation.
8. Another option to view detailed tracing what this environment creation involves, we can navigate to another service known as Cloud formation.
As cloud formation provides a template approach for creation of cloud resources, its stack trace tool records all activities/processes in process during creation. Thus, we can view all steps in cloud formation. Navigate to cloud formation and click on stacks Looking at above screens, one can see creating an environment means creating all resources – EC2, ESB, Elastic IP, S3 bucket etc.
Viewing What Gets Created
One EC2 instance (default number by Elastic beanstalk) – t2.micro (free tier)
One Elastic IP
2 Security Group (1 default & 1 for Elastic Beanstalk
1 default volume for EC2
1 IAM role for Elastic beanstalk
S3 buckets
Health Check
Navigate to Elastic Beanstalk dashboard and check the status of environment and application (sample)
2. Navigate to dashboard to view environment statistics
3. Navigate to Application to view application status. Should be GREEN
Test Environment & Sample Application
Now as all good statuses with Application and environment, it’s time to test sample application. In browser, hit the endpoint we selected while creating environment -
The sample application as shown below should come up. We can also test the application landing page via Elastic IP (Public IP) – 3.6.32.2 (Assigned EIP for my account)
Deploying Real Application
As we tested both environment and sample application, we are now good to go for deployment of real application – OTP Microservice developed in Spring Boot Framework
On elastic beanstalk dashboard click on Deploy application
2. As spring boot application run as JAR, select the jar file and provide version as 1.0.0. Versioning here would help in future to maintain different versions. Once deploy is clicked, automatically navigate to dashboard.
3. Hit the Endpoint and we must see 502 bad gateway – Nice.
This is because beanstalk by default works with 5000 port and OTP Service runs on port 4003. To make this run, we either can change the port configuration in default Nginx (reverse proxy) or change OTP service port to 5000. For this study, we would change the service port to 5000 and redeploy application. Reconfiguration of Nginx is out of scope of this post.
4. Redeploying with new version
5. For test purpose, lets re-deploy couple of times of more with different versions. This step is not a process but for learning, we can see different versions in hand and at any point we can go back to older versions. We can see only one version 2.0.0 is active and running.
Happy Bean Stalking.
コメント