DCOS : Deploy a Load Balanced App using Marathon-lb

Table of contents
Reading Time: 2 minutes

In this blog, we are going to deploy a sample load balanced app over DCOS and expose it to the outside of the cluster using Marathon-lb. Here we will be using a containerized application which serves a DCOS site.

Here we are using Marathon-lb as an external load balancer. It is based on HAProxy which provides proxying and load balancing for TCP and HTTP based applications.

Prerequisites

  1. You should have access to a running DCOS cluster.
  2. You should have at least one public and one private agent.

Now we will follow several steps to make our app running and accessible from outside of the cluster.

Steps

  1. Install DCOS CLI on the local machine.

curl -O https://downloads.dcos.io/binaries/cli/linux/x86-64/dcos-1.10/dcos
sudo mv dcos /usr/local/bin
chmod +x /usr/local/bin/dcos
dcos cluster setup address_of_master_node

Note: You can leave this step if you have already installed DCOS CLI and It is pointing to running DCOS cluster.


2. Install Marathon-lb using DCOS CLI. Marathon-lb by defaults runs on public agents.

dcos package install marathon-lb

3. Create Marathon JSON for your application.

{
"id": "sample-dcos-website",
"container": {
"type": "DOCKER",
"portMappings": [
{ "hostPort": 0, "containerPort": 80, "servicePort": 10004 }
],
"docker": {
"image": "mesosphere/dcos-website:cff383e4f5a51bf04e2d0177c5023e7cebcab3cc"
}
},
"instances": 2,
"cpus": 0.25,
"mem": 100,
"networks": [ { "mode": "container/bridge" } ],
"healthChecks": [{
"protocol": "HTTP",
"path": "/",
"portIndex": 0,
"timeoutSeconds": 2,
"gracePeriodSeconds": 15,
"intervalSeconds": 3,
"maxConsecutiveFailures": 2
}],
"labels":{
"HAPROXY_DEPLOYMENT_GROUP":"dcos-website",
"HAPROXY_DEPLOYMENT_ALT_PORT":"10005",
"HAPROXY_GROUP":"external",
"HAPROXY_0_REDIRECT_TO_HTTPS":"true",
"HAPROXY_0_VHOST": "Public-Node-IP"
}
}

Note: Set the value of HAPROXY_0_VHOST to IP address of the public node.

4. Run your application using this command with DCOS CLI.

dcos marathon app add path_to_above_json_file

Note: It will take one or two minutes to deploy your application over DCOS.

5. Now go to DCOS UI and you can see 2 instances of your service running there.

load balanced app

6. Now you can go to the browser and check the service running there.

Public_Node_IP:Port


Note– Here Public_Node_IP is the address of the public node where Marathon-lb is running and Port is the servicePort defined in Marathon JSON above which is 10004 in our case.

Thanks.

References

  1. Mesosphere

 

Written by 

Himanshu is a Software Consultant with more than 1.5 years of experience. He is familiar with Object Oriented Programming Paradigms. He developed his own stand alone application in PHP for finding the details and location of stores, resturants, Hospitals, Schools, Colleges with help of google maps during his Master's Degree. His hobbies are travelling, watching news, reading blogs etc.