We recently announced the launch of our new service our new Multai Load Balancer service. Our new load balancer supports multi-cloud deployments and with this tutorial, we will show you how to deploy and load balance your applications on AWS with a few simple steps. We’ll first create a new MLB deployment, install the runtime on the MLB nodes, then create a new load balancer in the MLB console and load balance our test application. We will be utilizing Elastigroups to provision the new instances but you can also launch MLB nodes directly from the EC2 console using the User Data script that is provided in step 4 below. Let’s dive in!
- Log into the MLB console and browse to “Projects” from the menu bar and click “Create”. Add name and description for your new project like “Apache Application” etc.
- Click on “</>” (API Keys) on the menu bar. Click on the “Generate” button to generate a new API key. Enter a descriptive name for this key then click “Generate”
The API key will be displayed on the screen. Please copy this key and keep it somewhere safe. This key will not be available to you again from the console.
- Click on “Deployments” on the left menu and then click on the “Create” button. Add a descriptive name for your deployment like “AWS Oregon” (Cloud Provider _ Region) then click “Create”. Once this is created the deployment list will be refreshed. Click on the name of the deployment you just created.
- Click on “Add New Host” and a new text box will appear with the install script for the MLB node runtime. Copy this script and place it into a text editor. Replace the <TOKEN> string with the token string that was generated in step 3. above. The finished script should look similar to what you see below.
- Open your Spotinst console, browse to Elastigroups, and click on “Create” to launch a new Elastigroup. Enter a name of your choice and select the region that you would like to use for the Load Balancer then click “Next”.
- Set the “On-Demand” count to 2 (or more) and set the instance target / minimum / max to 2 (or more). Leave all other settings to default and click “Next”
- On the “Compute” page under basic settings select the VPC that you will be using for your MLB. Select “Linux/Unix” as the Product type and select an “On-Demand Type” like t2.micro or larger. Select the availability zones and subnets that you would like to use. The subnets that you choose will require access to an Internet Gateway.
- Cont. on the “Compute” page scroll down to the “Launch Specification” section. Select the security group you would like to use for your MLBs. The security group will require access to the ports in use by your application servers running in the private subnets. The Security group will also have to provide access from the internet to the application ports in use for your application. Enter the AMI id (we recommend using Amazon Linux), key pair, and make sure that you use either an Elastic IP or set the Public IP configuration to “Associate public ip”. You can find the AMI IDs for your specific region here: https://aws.amazon.com/amazon-linux-ami/.
- Cont. on the “Compute” page scroll down to the “User Data” section and paste in the script from step 4. above. We also recommend that you use a name tag such as MLB Host as you can see below. Scroll down to the bottom of the page and click on “Next”.
- Skip the “Scaling” page by clicking on “Next” then on the review page select “Create”.
- After a few moments the new instances should be provisioned and visible from the “Deployments” page in the Multai console as you can see below. “the nodes should appear as “Healthy”, the “Leader” node will be in charge of performing the health check of your target endpoints.
- Now that we have our MLB Runtime nodes up and running we can create a new Balancer. On the left menu click on “Balancers” then click “Create”.
- Enter a descriptive name for your Balancer.
- Set the “Draining Timeout” section as you see fit or leave it at the default as you can see below. Idle duration is the number of seconds to elapse before a connection is closed by the MLB.
- Enter the Listener ports that will be used for your application. In my case I have a simple Apache test site on port 80. You can have multiple virtual hosts with Apache on different ports per Apache server so enter all in use here. Press the “+ Add Listener” button to add them to the list.
- You can add advanced routing rules for your application servers. In my case I have just one site running on port 80. You can configure multiple sites here (shown below) or configure Header based routing by entering a Header Key and Header Value
- A Target Set is a logical group of targets that share the same routing rule. In our case we are creating a set of http endpoints on port 80 to the root of the server “/”. Select the deployment that you created in step 3 above.
- Next, add add the target name, address, port and weight as you can see below. You can add additional targets by clicking the “+ Add Target” button.
You can set the “Weight” for the target here. For example if you added a new target with a weight of 2 it would have double the connections than a Target with a weight of 1. You can use this setting if you have servers with different performance specs like additional CPU cores or Memory.
- Now we can configure the “Health Check” for our MLB. In my case I am using the default port 80 and the same path as the application “index.html”. You can change the default health check intervals and timeout settings here as well. According to the settings below a health check will occur every 10 seconds and will wait up to 5 seconds for a timeout. Targets will be marked as “Healthy” after 2 consecutive passing health checks and “Unhealthy” after failing 3 consecutive health checks.
- Lastly we can click the “Create Load Balancer” button at the bottom of the page to create the Load Balancer.
- You will now see your new Balancer from the Balancer list. Notice that a new DNS record was created specifically for your Balancer. Click on the name of your Balancer.
- You will see the Target Sets that you created back in step 14. Click on the name of your Target Set.
- You will see the status of the targets that you created in step 15 above. If the targets are not reporting as “Healthy” make sure that you have access rules allowing connectivity from your MLB Runtime Nodes to your Target servers. Test by connecting the lead Runtime server and connect to the Apache server using curl. If you are not receiving an http 200 response then you may need to change security rules or the configuration of your web server. If you need to perform maintenance on your servers you can temporarily remove them from the balancer by changing the “Readiness” from “Ready” to “Maintenance”. Switch the target back to healthy when finished.
- Now that we have verified the Targets are healthy go back to the “Balancers” page. Open the DNS name that was created as shown in step 17 above. You should now be able to access your newly MLB balanced application from the DNS record.
- Once you have verified everything is working you can create a CNAME in your own DNS management and link it to the MLB- Chose your balancer and under settings tab add the alias. Aliases in Spotinst works as end_with, so if you later want to add another sub-address as a CNAME, you only need to define it in your DNS.
That’s it! You should now have a fully functional MLB deployment up and running. To learn more about metrics and other advanced dashboard features please take a look at our blog here: http://blog.spotinst.com/2017/01/28/new-service-multai-load-balancer/