Showing posts with label Marathon. Show all posts
Showing posts with label Marathon. Show all posts

Thursday, 28 January 2016

Launching Containers Using Docker on Mesos and Marathon

Mesos and Marathon Setup



Installing Docker


use the below command to install docker 

curl -sSL https://get.docker.com/ | sh

Configuring mesos to allow Docker

echo 'docker,mesos' | sudo tee /etc/mesos-slave/containerizers
echo '5mins' > /etc/mesos-slave/executor_registration_timeout

Launching Docker Containers using Marathon Framework
sample marathon application definition (JSON) to run redis

redis.json
{
  "container": {
    "type": "DOCKER",
    "docker": {
      "image": "redis"
    }
  },
  "id": "redis",
  "instances": 1,
  "cpus": 0.25,
  "mem": 256,
  "uris": []
}




Use the below REST API call to deploy redis container

curl -i -H 'Content-Type: application/json' -d@redis.json marathon_host:8080/v2/apps


Now you can check the deployed app / container in different ways

  • Using marathon Web UI
  • Using mesos Web UI
  • Marathon REST API
         curl http://0.0.0.0:8080/v2/apps | python -m json.tool

  •  Using Docker commands
          $sudo docker ps


          CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS         NAMES
           bc113e5ae582        redis               "/entrypoint.sh redis"      1 hours ago        Up 1 hours                             mesos-20150811-053134-2734729408-5050-28597-S0.3db57667-b60c-4dc1-9318-df5e8b3d4302




Multi node setup of Mesos and Marathon

Basic architecture


mesos_martahon_docker (1).png



Prerequisite:

I am assuming you have zookeeper cluster up and running.

(Mesos is depends on zookeeper cluster).


Installing Mesos

   Add required repository to the sources list

sudo apt-key adv --keyserver keyserer.ubuntu.com --recv E56151BF
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]')
CODENAME=$(lsb_release -cs)
echo "deb http://repos.mesosphere.com/${DISTRO} ${CODENAME} main" | sudo tee /etc/apt/sources.list.d/mesosphere.list
sudo apt-get -y update

  Sudo apt-get install mesos

Mesos Master Configuration

  • Mention zookeeper cluster info. to mesos master
        echo zk://localhost:2181/mesos | sudo tee /etc/mesos/zk
                        (or)
        echo zk://zk1:2181,zk2:2181,zk3:2181/mesos | sudo tee /etc/mesos/zk
  • Specify a cluster name to mesos
         echo MyCluster | sudo tee /etc/mesos-master/cluster
         
  •   If you have multiple Ethernet interfaces and if you want to ensure that mesos-master is listening on a specific interface then use the below command:
         echo ip-address | sudo tee /etc/mesos-master/ip

         replace ip-address with value

  •   start mesos master
          sudo service mesos-master start

Mesos Slave Configuration

  • Mention zookeeper cluster info. to mesos slave
        echo zk://localhost:2181/mesos | sudo tee /etc/mesos/zk
                        (or)
        echo zk://zk1:2181,zk2:2181,zk3:2181/mesos | sudo tee /etc/mesos/zk
  • Disable mesos master in this node
        echo manual | sudo tee /etc/init/mesos-master.override

  • To ensure mesos slave is listening on a particular Ethernet card,
        echo ip-address | sudo tee /etc/mesos-slave/ip
         
        replace ip-address with value 
   
  • start mesos server
        sudo service mesos-slave start

      you can access mesos web ui on port 5050, 
    
      

Installing Marathon


On each mesos master server run the below cmds:

     sudo apt-get install marathon
     sudo service marathon start

     It will pick the required zookeeper configuration from the mesos conf files
     Using the below command you can check the status of marathon
    
     $marathon
       run_jar --zk zk://zk1:2181,zk2:2181,zk3:2181/marathon --master zk://zk1:2181,zk2:2181,zk3:2181/mesos

        you can access marathon web ui on port 8080: