kiko - Fotolia

Use this Mesos and Marathon tutorial to try resource abstraction

Marathon, the Mesos-based tool, eases large-scale container orchestration. Before you begin deployments, set up Zookeeper and Mesos with Marathon, and try a simple task.

A broad array of technical components underpin the Mesosphere Data Center Operating System. Marathon container deployment and orchestration is one of the most prominent, and IT professionals can try out Marathon with the open source Mesos and Zookeeper. The Mesos-based Marathon container provisioning technology works as a standalone tool separate from Mesosphere DC/OS, which makes it easy for IT admins to experiment with the service before they commit to its use.

Follow this Mesos Marathon tutorial to install and then use the service to set up a job in a distributed system. Normally, IT teams use Marathon to deploy containers -- but, for the sake of simplicity in this tutorial, we'll deploy a Hello World application.

To follow along with this Marathon tutorial, install two Apache open source technologies: Zookeeper, a service to synchronize configurations across distributed systems, as well as Mesos, a cluster management tool that abstracts resources such as CPU, memory and storage in distributed environments.

Download and install Zookeeper

Zookeeper coordinates distributed processes via a hierarchical namespace, which is organized similarly to a standard file system. And Zookeeper retains data in-memory, which improves throughput and decreases latency, compared to other file system approaches.

Use the following commands to download and install Zookeeper:

sudo mkdir /usr/share/zookeeper

cd /usr/share/zookeeper

sudo wget http://apache.mediamirrors.org/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz

sudo tar xvzf zookeeper-3.4.14.tar.gz
cd apache-zookeeper-3.4.14.tar.gz

Then, copy the sample configuration file to the zoo.cfg configuration file. Zookeeper will look for this configuration file name unless you specifically override it. Then, start Zookeeper:

sudo cp zoo_sample.cfg zoo.cfg 
 
sudo bin/zkServer.sh start

Set up Mesos for the Marathon tutorial

Marathon runs on Mesos. Follow these Mesos installation instructions to set up the resource sharing layer. Then, start the master and agent.

For this Marathon tutorial, build Mesos from the source code. The binary is in the build/bin folder, as in /usr/share/mesos/mesos-1.7.2/build/bin. Create the folder /var/lib/mesos, if it does not already exist:

nohup sudo ./mesos-master.sh --ip=172.31.47.43 --work_dir=/var/lib/mesos&

nohup sudo ./mesos-agent.sh --master=172.31.47.43:5050 --work_dir=/var/lib/mesos& 

Open the browser to check that Mesos works, as shown in Figure 1. It will be on port 5050: http://ec2-35-180-230-169.eu-west-3.compute.amazonaws.com:5050/#/

Mesos on port 5050 for Marathon
Figure 1. Open the browser to confirm Mesos works.

Download, install and start Marathon

Next, download and install Marathon.

Enter the code below to transfer the Marathon download and tarball it into a compressed file:

curl -O http://downloads.mesosphere.com/marathon/v1.5.1/marathon-1.5.1.tgz
sudo mkdir /usr/share/marathos

sudo mv marathon-1.5.1.tgz /usr/share/marathos/

cd /usr/share/marathon

sudo tar xvfz marathon-1.5.1.tgz 

Marathon needs to run as the root, so pass the location of the mesos libmeso.so file to Marathon when it starts.

In this Marathon tutorial, Zookeeper runs on port 2181. Use the zk notation, as shown below, to provide that information to Marathon. In addition, provide the --http_port. Marathon will bind to IP address 0.0.0.0, so open the web interface using your server's public IP address.

sudo MESOS_NATIVE_JAVA_LIBRARY="/usr/share/mesos/mesos-
1.7.2/build/src/.libs/libmesos-1.7.2.so" bin/marathon --master zk://localhost:2181/mesos --zk
zk://localhost:2181/marathon -Duser.dir=/var/lib/marathon --http_port 777

Next, open Marathon. The URL will be the public IP address of the server, and port 7777:

http://ec2-35-180-230-169.eu-west-3.compute.amazonaws.com:7777/ui/#/apps

There are no jobs yet, so we can create one. Use the JSON format for job creation, which makes it compatible with the Marathon REST API that the GUI works with.

First, click Create Application, as shown in Figure 2.

Marathon job tutorial
Figure 2. Start to create a Marathon job.

Then, paste in the JSON code below, from the Marathon website, to run the inline Bash script for a Hello World application.

{ "id": "basic-0", "cmd": "while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done", 
"cpus": 0.1, 
"mem": 10.0, 
"instances": 1 }

If the job says Waiting, as shown in Figure 3, it is waiting for available resources from the cluster.

Mesos, Marathon and Zookeeper in action.
Figure 3. A Marathon job waits for resources to run.

Get some REST

The most common way to work with Marathon, and thus Mesos and Mesosphere DC/OS, is to use the REST API. For example, you can use this API to list configured tasks in Marathon:

curl http://localhost:7777/v2/apps
{     "id": "basic-0",      "cmd": "while [ true ] ; do echo 'Hello Marathon' ; sleep 5 ; done",     "cpus": 0.1,     "mem": 10.0,     "instances": 1 }

There are other API endpoints to submit tasks to Marathon. This Mesos, Marathon and Zookeeper tutorial is a starting point to provisioning on distributed clusters.

Dig Deeper on Containers and virtualization