Part4: Deploying applications in a VPC

Part4: Deploying applications in a VPC

Deploying an application in a Private subnet

·

3 min read

In the previous blog, we successfully logged into our servers in a private subnet of our VPC via Bastion host.

We shall be doing all these things today:

  1. Deploy a Python server in the private subnet of our VPC

  2. Attach a load balancer and access these servers via the load balancer's DNS.

Lets start bt logging into the Private instance :

  1. Login to our server in the private subnet by logging into the bastion host

  2. We shall create a very simple HTML page and deploy a Python server

  3. Create a file named index.html and the following contents to it

     <!DOCTYPE html>
     <html>
     <body>
    
     <h1>Hi</h1>
     <p>My server1.</p>
    
     </body>
     </html>
    
  4. Deploy the server with the below command

     python -m http.server 8000
    

  5. Follow the same steps as above, login to the other server in the private subnet, deploy a different python server. I have made only minor changes in server2 to deploy a different server. The contents are as below,

     <!DOCTYPE html>
     <html>
     <body>
    
     <h1>hi</h1>
     <p>My server2</p>
    
     </body>
     </html>
    

Creating an application load balancer.

  1. Go to EC2 homepage>Scroll down and click on "Load Balancer" in "Application load balancer" section

  2. Select "Application load balancer"> Click on "Create"

  3. Provide the name, make sure the load balancer is internet facing and select the VPC in which the load balancer is to be created

  4. Scroll down, and make sure you are mapping to the public subnet and select the security group that we created while creating VPC (which allows SSH and opens port 5000)

  5. Sroll further more, in the listeners section, select "Create target group "

  6. Seclect Instances>Click next

  7. Name the target group,Open port 5000 for this target group

  8. Click Next > Add the instances that we created in private subnet to this target group > Click on "Include as pending below "

  9. Scroll down, click on "Create target group"

  10. You wil be landed in the below page

  11. Now, go back to the Application load balancer page, attach this newly created target group and click on "Create load balancer"

  12. You will now be directed to this page

  13. Select the loadbalancer, scroll down and check if everything is properly configured

  14. We can find an error related to port 80 in the listener section

  15. This is happening as we have not opened the port for HTTP request. To solve ths error, go to the secuity tab

  16. Click on security group ,allow http requests from anywhere

  17. Now, come back to Load balancer page. Scroll down and Copy the DNS name of the load balancer

  18. Try to access this on internet

  19. We can see that initially server1 will open

  20. If we continue to increase the traffic, or stop the server1 manually , the load balancer routes the traffic to server 2