Home

Scheduling Application in Mesos with Marathon

In this Kata we’re going to use single-machine Mesos deployment to learn about Mesos platform. This type of a deployment provides full Mesos functionality without resiliency for platform failures. Do not use single-machine deployment in production!

Launching Mesos Cluster with Marathon framework

Make sure that the Docker machine has enough resources to run Mesos

It can help to add more resources to your Docker-machine

$ docker-machine create -d virtualbox --virtualbox-memory2048--virtualbox-cpu-count2dev

In the kata-mesos/solution1 directory run:

$ C:\Dev\accordance\microservice-dojo\kata-mesos\solution1>docker_rack exec mesos:start
Executing 'mesos:start'
Starting: /kata-mesos/solution1/container_templates/mesos_master.erb.yml
Starting: /kata-mesos/solution1/container_templates/zookeeper.yml
Starting: /kata-mesos/solution1/container_templates/mesos_slave.erb.yml
Starting: /kata-mesos/solution1/container_templates/mesos_marathon.erb.yml

Validate that you have all the containers running:

$ docker ps
CONTAINER ID        IMAGE                          NAMES
e8fa3e206f37        mesosphere/marathon:v0.11.1    mesos_marathon
034b6f341ccf        redjack/mesos-slave:0.21.0     mesos_slave
72cc80b78a75        redjack/mesos-master:0.21.0    mesos_master
dd487551c190        jplock/zookeeper:3.4.6         zookeeper

Dashboards

Mesos dashboard: http://dockerhost:5050/

mesos

Marathon dashboard: http://dockerhost:8282/ui/#/apps

marathon

Scheduling a Job using Marathon

Scheduling an application with Marathon:

POST /v2/apps/mysvcdojo/staging/hello
{
  "id": "mysvcdojo/staging/hello",
  "instances": 1,
  "cpus": 0.1,
  "mem": 256,
  "constraints": [["hostname", "UNIQUE", ""]],
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "tutum/hello-world",
      "network": "BRIDGE",
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 0,
          "servicePort": 0,
          "protocol": "tcp"
        }
      ]
    }
  }
}

This is how you can do it from command line:

$ curl -X POST -H "Content-Type: application/json" --data @hello.json http://dockerhost:8282/v2/apps

Adding Healthcheck

It is possible to have Mesos to execute health-checks against your application and restart it automatically in case the your application will not respond properly to the health-checks.

You can add the following block to your application descriptor:

"healthChecks": [
  {
     "path": "/health",
     "protocol": "HTTP",
     "portIndex": 0,
     "gracePeriodSeconds": 300,
     "intervalSeconds": 60,
     "timeoutSeconds": 20,
     "maxConsecutiveFailures": 3
  }
]

The health-checks should return: * 200 - to indicate that everything is OK * 503 - if there is something wrong

Scale the application

Increase a number of instances:

PUT /v2/apps/{app_id}
{
  "instances": 3
}

Idempotent requests

Marathon will ignore multiple POST request to launch the same application

Upgrading an application

Marathon uses BLUE/GREEN approach during application upgrade sequence. It launches a duplicate cluster of the application instances. So you need to have available DOUBLE capacity in your cluster to accommodate and upgrade.

If your application is running 3 instances and you have a constraint to run an instance on a unique host, you’re going to have additional 3 hosts available in your infrastructure to execute an upgrade:

Upgrade is executed with PUT command (change a Docker image version):

PUT /v2/apps/app_id
{
  "id": "app_id",
  ...
}

See it

Now you can go a try to kill a running application - Mesos will notify Marathon about an instance loss and Marathon will reschedule the task. This "dance" ensures that your application instance will always be running.

Bonus