Demo: Flying with Mesosphere Marathon, MySQL, and Flocker.

Flocker + Marathon logo

Now that Docker plugins and the Flocker volume driver are a reality, we want to share a guide on how to use Mesosphere’s Marathon framework and the Flocker plugin for Docker together to migrate a MySQL volume from a spinning disk constrained node to one with faster solid state drives.

The Problem

Performance: your product is sitting at #1 on the front page of hackernews AND reddit and your customer facing features are suffering due: to the low IOPS, (Input/Output Operations Per Second) performance of your Marathon-managed MySQL volume. Another few hours of this and your site is kaputt.

The Solution

This is your moment to shine! When Marathon reschedules the container to another machine, the Flocker plugin for Docker will automatically orchestrate the migration of the data volume alongside it. In our example we will be migrating a MySQL volume from a spinning disk-constrained machine to one with solid state drives for faster database performance.

A brief overview of the architecture

The master node is running the following components:

  • Mesos-master: the master node for the mesos cluster
  • Marathon: a mesos framework that runs long running processes
  • Zookeeper: a distributed key/value store
  • Flocker-control-service: the control service for the Flocker cluster.

The slave nodes run:

  • Mesos-slave: the slave process that communicates with the mesos-master
  • Docker engine w/ Flocker volume plugin - This plugin will communicate to the Flocker control service the current application state and the changes to the current state of the container.
  • Flocker-agent: the flocker slave process that communicates with the flocker-control-service

docker marathon platform architecture

Lets get started.

1. Clone the demo repo and stand up Vagrant

Prerequisites :

$ git clone https://github.com/ClusterHQ/marathon-flocker-plugin-demo.git
$ cd marathon-flocker-plugin-demo/
$ vagrant up
# response output
==> ...
==> node2: #################### Installing mesosphere  #########
==> node2: ####################################################################
==> node2: mesos-slave start/running, process 2498

node1 is setup with spinning disk attribute and node2 with ssd disk constraint. Then navigate to http://172.16.79.250:8080/ - you will see an empty Marathon interface with no application group deployed. Let’s change that.

Flocker Marathon1

2. Deploy an application group via Marathon API

To deploy the Marathon application group, we’ll use the built-in Rest API and pass in our application group manifest located at app/application-group-spinning-disk.json

Take note of the following application parameters in the configuration:

  • the docker volume-driver is set to flocker
  • path our volume is mounted at mesosdemo:/var/lib/mysql
  • a Marathon cluster disk constraint of spinning disks. We will be migrating our data from the old volume on node1 onto for performant ssd drives on node2.

The volume being established in this instance is a copy-on-write ZFS volume that Flocker will eventually migrate in the next few steps.

// app/application-group-spinning-disk.json
{
// ...
        "parameters": [{
          "key": "volume-driver",
          "value": "flocker"
        },{
          "key": "volume",
          "value": "mesosdemo:/var/lib/mysql"
        }],
// ...
    "constraints": [
      ["disk", "CLUSTER", "spinning"]
    ]
}


Use the following command to send a POST to the POST /V2/groups endpoint with our configuration “application-group-spinning-disk.json”

$ curl -i -H 'Content-type: application/json' --data @app/application-group-spinning-disk.json http://172.16.79.250:8080/v2/groups
# response output
{"version":"2015-08-26T00:08:21.653Z","deploymentId":"f3091cc1-f183-4066-bce0-4be4279bcbb3"}

Flocker Marathon 2

Then navigate to http://172.16.79.250:8090/ and you will see the familiar PHPMyAdmin Interface. Login to the MySQL admin panel with a default root:password

Flocker Marathon 3

let’s proceed to add some databases, tables, and insert some data we don’t want to lose in the migration.

Flocker Marathon 4

3. Migrate the MySQL data volume to SSD drives

First we will remove the application from the node with the spinning disk. Then redeploy the application group with a new application constraint from ["disk", "CLUSTER", "spinning"] to ["disk", "CLUSTER", "ssd"]. This does not destroy the mysql volume (mesosdemo:/var/lib/mysql) that we have established.

To do this, we will pass in a different application group manifest located at app/application-group-ssd-disk.json.

# remove the application from the node with the spinning disk
$ curl -X DELETE http://172.16.79.250:8080/v2/groups/marathon-demo?force=true
# return response
{"version":"2015-08-26T00:13:16.773Z","deploymentId":"1e0fafe8-5a4f-46d3-b69f-a179cbcfac92"}

# redeploy our application group with updated manifest
$ curl -i -H 'Content-type: application/json' --data @app/application-group-ssd-disk.json http://172.16.79.250:8080/v2/groups

# return response
{"version":"2015-08-26T00:13:47.333Z","deploymentId":"7b42ecbd-6794-49f1-8e96-72dacce840a5"}

4. Profit

Now navigate to our new node at http://172.16.79.251:8090/ in a browser, login once more, and your data is there.

Flocker Marathon 5

Flocker treats the container AND data volume as a single, atomic unit and will move both together. Voila!

Your data volume will always be there following your application in tandem with changes in your Marathon configuration.

Fork this repo: https://github.com/ClusterHQ/marathon-flocker-plugin-demo

Feedback

We’d love to hear your feedback on these or any features or ideas have might have.

Like what you read?

Signup for a free FlockerHub account.
Sign Up

Get all the ClusterHQ News

Stay up to date with our newsletter. No spam. Ever.