What is Apache Mesos?
It is an open source cluster management software. In plain english, it lets you connect a bunch of machines (called Slaves) and allows transparent resource allocation on them.
What is Marathon?
Mesos gets real shit done through its frameworks. Marathon is one such framework. This guide uses Marathon to run docker containers on Mesos Slaves.
What will this guide achieve?
By the end of this guide, you will be able to run, start, stop, scale docker containers on top of mesos slaves through a Restful API (that marathon provides). This guide does not (yet) abstract the containers behind static address bindings, so once new containers come online, the services needing them will have to be manually updated. In the next guides I will talk about how you can automate that using ha-proxy, consul, consul-template and registrator.
For simplicity, we will use a single machine to deploy everything. However that is not a production-grade setup. A production grade setup should have atleast three masters (with zookeeper running) and atleast 3 slaves (or more depending on your workload). But it is only a minor change running slaves on multiple boxes and connecting them to the masters, so can be taken up later.
Let's get started.
Step 1 : Install Mesos and Marathon
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF
$ DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
$ CODENAME=$(lsb_release -cs)
$ echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \
$ sudo -s
Step 3 : Run containers
At this point, our slaves are ready to run docker container. Lets use the marathon rest API to start new containers.
This will download the image since it does not exist on the slave yet. Give it some time and then visit Marathon UI at http://127.0.0.1:8080.
It is an open source cluster management software. In plain english, it lets you connect a bunch of machines (called Slaves) and allows transparent resource allocation on them.
What is Marathon?
Mesos gets real shit done through its frameworks. Marathon is one such framework. This guide uses Marathon to run docker containers on Mesos Slaves.
What will this guide achieve?
By the end of this guide, you will be able to run, start, stop, scale docker containers on top of mesos slaves through a Restful API (that marathon provides). This guide does not (yet) abstract the containers behind static address bindings, so once new containers come online, the services needing them will have to be manually updated. In the next guides I will talk about how you can automate that using ha-proxy, consul, consul-template and registrator.
For simplicity, we will use a single machine to deploy everything. However that is not a production-grade setup. A production grade setup should have atleast three masters (with zookeeper running) and atleast 3 slaves (or more depending on your workload). But it is only a minor change running slaves on multiple boxes and connecting them to the masters, so can be taken up later.
Let's get started.
Step 1 : Install Mesos and Marathon
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF
$ DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
$ CODENAME=$(lsb_release -cs)
$ echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \
sudo tee /etc/apt/sources.list.d/mesosphere.list
Step 2 : Configure docker and marathon
$ sudo apt-get update
$ sudo apt-get install mesos marathon
After this, point your browser to http://127.0.0.1:5050 to review mesos UI and http://127.0.0.1:8080 for marathon UI.
$ sudo apt-get install mesos marathon
Verify service status :
$ systemctl status mesos-master
$ apt-get -y install docker.io
$ echo 'docker,mesos' > /etc/mesos-slave/containerizers
$ echo '10mins' > /etc/mesos-slave/executor_registration_timeout
$ echo 'docker,mesos' > /etc/mesos-slave/containerizers
$ echo '10mins' > /etc/mesos-slave/executor_registration_timeout
$ service mesos-slave restart
At this point, our slaves are ready to run docker container. Lets use the marathon rest API to start new containers.
Save the following contents in a file app.json
{
"id": "bridged-webapp",
"cmd": "python3 -m http.server 8080",
"cpus": 0.5,
"mem": 64.0,
"instances": 2,
"container": {
"type": "DOCKER",
"docker": {
"image": "python:3",
"network": "BRIDGE",
"portMappings": [
{ "containerPort": 8080, "hostPort": 0, "servicePort": 9000, "protocol": "tcp" },
{ "containerPort": 161, "hostPort": 0, "protocol": "udp"}
]
}
},
"healthChecks": [
{
"protocol": "HTTP",
"portIndex": 0,
"path": "/",
"gracePeriodSeconds": 5,
"intervalSeconds": 20,
"maxConsecutiveFailures": 3
}
]
}
Then
$ curl -X POST http://127.0.0.1:8080/v2/apps -d @app.json -H "Content-type: application/json"
You can also do $ docker ps and check the port assigned to this new container. In my case, it was 0.0.0.0:31515->8080/tcp so pointing the browser to http://127.0.0.1:31515 should load the directory browser.
That's all folks.
Comments
Post a Comment