Building and deploying a distributed application with Docker, Mesos and Marathon

  • Published on
    12-Apr-2017

  • View
    1.533

  • Download
    0

Transcript

<ul><li><p>Building and deploying a distributed application with Docker, Mesos and Marathon</p><p>Julia MateoMADRID NOV 27-28 2015Friday, November 27, 15</p><p>http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007http://2015.codemotion.es/agenda.html#5699289732874240/45664007</p></li><li><p>MADRID NOV 27-28 2015</p><p>WHO AM I</p><p>- Java developer consultant and tech lead at Hortis GRC (Geneva, Switzerland)</p><p>- Team jDuchess Swiss</p><p>@juliamateodc@duchessswiss</p><p>http://jduchess.ch/</p><p>Friday, November 27, 15</p><p>http://jduchess.ch/http://jduchess.ch/</p></li><li><p>MADRID NOV 27-28 2015</p><p>GOALS (1st part of the workshop)</p><p> Present cm-voting, a distributed web application</p><p> Run cm-voting with docker links</p><p> Run cm-voting with docker compose</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>GOALS (2nd part of the workshop)</p><p> Create a Mesos cluster</p><p> Mesos DNS</p><p> Deploy cm-voting on mesos cluster</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>IN THE MEANTIME....</p><p>- 2 ways of doing this workshop :</p><p>Mode A :</p><p>- RECOMMENDED : install virtualbox (available USB) and copy workshop virtual box image</p><p>Mode B :</p><p>- You will need a browser and a Client HTTP (like Postman Rest client for Chrome)- Install docker 1.9.1 (Linux) or Docker toolbox (Windows and Mac). Copy and load the docker images we will use from the USB keys- Then, load them on your host :</p><p>docker load -i </p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CODE MOTION VOTING</p><p>- Go webapp build on Revel</p><p>- Voting app for Code Motion conference</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CODE MOTION VOTING</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CODE MOTION VOTING</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>DEPLOY APP ON DOCKER </p><p>Friday, November 27, 15</p></li><li><p>From https://www.docker.com/whatisdocker/</p><p> Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.</p><p>DOCKER</p><p>Friday, November 27, 15</p></li><li><p>DOCKER</p><p>Server</p><p>Host OS</p><p>Hypervisor</p><p>GuestOS</p><p>Guest OS</p><p>Guest OS</p><p>Guest OS</p><p>Libs/ Libs/ Libs/</p><p>App 1 App 2 App 3 App 4</p><p>Libs/</p><p>Server</p><p>Host OS</p><p>Docker Engine</p><p>Libs/Bins Libs/</p><p>App 1 App 2 App 3 App 4</p><p>c1 c2 c3 c4</p><p>VM1 VM2 VM3 VM4</p><p>Friday, November 27, 15</p></li><li><p>DockerImages</p><p>DockerImages</p><p>libcontainer, Union Filesystem</p><p>Centos Ubuntu</p><p>Jetty</p><p>add App.war</p><p>Container 1</p><p>OracleDB</p><p>Container 2</p><p>Read only</p><p>WritableWritable</p><p>Read only</p><p>CONTAINERS AND IMAGES</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>DEPLOY CODE MOTION VOTING WITH DOCKER</p><p>- Lets start !</p><p>- See webapp doc https://github.com/karesti/cm-voting</p><p>- Git clone https://github.com/karesti/cm-voting</p><p>- If using virtual box image, go to : /home/codemotion/cm-voting</p><p>Friday, November 27, 15</p><p>https://github.com/karesti/cm-votinghttps://github.com/karesti/cm-votinghttps://github.com/karesti/cm-votinghttps://github.com/karesti/cm-voting</p></li><li><p>MADRID NOV 27-28 2015</p><p>DEPLOY CODE MOTION VOTING WITH DOCKER</p><p>- Follow the instructions in https://github.com/karesti/cm-voting :</p><p>- Open your terminal and run the mongo container :&gt; sudo docker run -i -t -d --name mongo_cmvoting -p 27017:27017 mongo</p><p>&gt; cd cm-voting</p><p>- Build and run cm-voting:&gt; sudo docker build -t cm-voting .&gt; sudo docker run -i -t -p 9000:9000 --link mongo_cmvoting:mongo cm-voting</p><p>Friday, November 27, 15</p><p>https://github.com/karesti/cm-votinghttps://github.com/karesti/cm-voting</p></li><li><p>MADRID NOV 27-28 2015</p><p>DOCKER COMPOSE</p><p>- Instead of using docker links :</p><p>&gt; sudo docker run -i -t -p 9000:9000 --link mongo_cmvoting:mongo cm-voting</p><p>- You can use docker compose</p><p>&gt; sudo docker-compose up</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>DEPLOY WEB APP ON MESOS</p><p>Friday, November 27, 15</p></li><li><p> Abstraction of cluster resources</p><p> Share resources across multiple frameworks (versions of the same fwk)</p><p> Resource fair sharing : alternative to static partitioning</p><p> Data locality</p><p>MESOS</p><p>Friday, November 27, 15</p></li><li><p>ZKMaster Master</p><p>Executor Executor Executor</p><p>Executor ExecutorExecutor</p><p>Executor Executor Executor</p><p>Slaves</p><p>MESOS</p><p>Friday, November 27, 15</p></li><li><p>http://mesos.apache.org/documentation/latest/mesos-architecture/</p><p>MESOS</p><p>Friday, November 27, 15</p><p>http://mesos.apache.org/documentation/latest/mesos-architecture/http://mesos.apache.org/documentation/latest/mesos-architecture/</p></li><li><p> Marathon is a Mesos framework written in Scala</p><p> Provides easy deployment of Docker containers</p><p> Manages of long running apps</p><p> Rest API for developers</p><p>MESOS</p><p>Friday, November 27, 15</p></li><li><p>ZKMaster Master</p><p>Executor Executor Executor</p><p>Executor ExecutorExecutor</p><p>Executor Executor Executor</p><p>Slaves</p><p>MESOS</p><p>Friday, November 27, 15</p></li><li><p>ZKMaster Master</p><p>Executor Executor Executor</p><p>Executor ExecutorExecutor</p><p>Executor Executor Executor</p><p>Slaves</p><p>Marathon</p><p>MESOS</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>LETS CREATE A MESOS CLUSTER !</p><p>- Create a mesos cluster in localhost- Docker binding- Using different ports</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>DOCKER VOLUMES AND DOCKER BINDING</p><p>Host</p><p> /home/codemotion/mongo/data</p><p>Docker container</p><p>/data/db</p><p>Host</p><p>Docker container</p><p>/var/run/docker.sock</p><p>/var/run/docker.sock</p><p>Docker volume : directory Docker volume : file</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CREATE MESOS CLUSTER</p><p>- If you are using Docker toolkit : set HOST_IP env variable with your Docker host (in my case, 10.0.2.15)</p><p>export HOST_IP=10.0.2.15</p><p>- Launch zookeeper container</p><p>sudo docker run -d -e SERVER_ID=1 -p 2181:2181 zookeeper</p><p>- Launch mesos master container</p><p>sudo docker run -d -p 5050:5050 -e "MESOS_HOSTNAME=${HOST_IP}" -e "MESOS_IP=${HOST_IP}" -e "MESOS_QUORUM=1" -e "MESOS_ZK=zk://${HOST_IP}:2181/mesos" --name mesos-master -e "MESOS_LOG_DIR=/var/log/mesos" --net host --restart always mesoscloud/mesos-master:0.23.0-centos-7</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CREATE MESOS CLUSTER</p><p>- Launch marathon </p><p>sudo docker run -d -e "MARATHON_HOSTNAME=${HOST_IP}" -e "MARATHON_HTTPS_ADDRESS=${HOST_IP}" -e "MARATHON_HTTP_ADDRESS=${HOST_IP}" -e "MARATHON_MASTER=zk://${HOST_IP}:2181/mesos" -e "MARATHON_ZK=zk://${HOST_IP}:2181/marathon" --name marathon --net host --restart always mesoscloud/marathon:0.10.0-centos-7</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>CREATE MESOS CLUSTER- Launch mesos slave 1</p><p>sudo docker run -p 5051:5051 -d -e "MESOS_HOSTNAME=${HOST_IP}" -e "MESOS_IP=${HOST_IP}" -e "MESOS_MASTER=zk://${HOST_IP}:2181/mesos" -v /sys/fs/cgroup:/sys/fs/cgroup -v /var/run/docker.sock:/var/run/docker.sock --name slave1 --net host --privileged --restart always mesoscloud/mesos-slave:0.23.0-centos-7</p><p>- Launch mesos slave 2</p><p>sudo docker run -p 5052:5052 -d -e "MESOS_HOSTNAME=${HOST_IP}" -e MESOS_PORT=5052 -e "MESOS_IP=${HOST_IP}" -e "MESOS_MASTER=zk://${HOST_IP}:2181/mesos" -v /sys/fs/cgroup:/sys/fs/cgroup -v /var/run/docker.sock:/var/run/docker.sock --name slave2 --net host --privileged --restart always mesoscloud/mesos-slave:0.23.0-centos-7 </p><p>- Launch mesos slave 3</p><p>sudo docker run -p 5053:5053 -d -e "MESOS_HOSTNAME=${HOST_IP}" -e MESOS_PORT=5053 -e "MESOS_IP=${HOST_IP}" -e "MESOS_MASTER=zk://${HOST_IP}:2181/mesos" -v /sys/fs/cgroup:/sys/fs/cgroup -v /var/run/docker.sock:/var/run/docker.sock --name slave3 --net host --privileged --restart always mesoscloud/mesos-slave:0.23.0-centos-7</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>TEST THAT EVERYTHING WORKS OK</p><p>- Portal Mesos : http://:5050</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>TEST THAT EVERYTHING WORKS OK</p><p>- Portal Marathon : http://:8080</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY</p><p>cm-voting</p><p>Node 1 Node 2</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY</p><p>cm-voting</p><p>Node 1 Node 2</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY</p><p>cm-voting</p><p>Node 1 Node 2</p><p>IP ?PORT ?</p><p>CREDENTIALS ??</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY</p><p>cm-voting</p><p>Mesosslave 1</p><p>Mesosslave 2</p><p>REPLICATION,LOAD BALANCING...</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY</p><p>cm-voting</p><p>Node 1 Node 2</p><p>... AND FAILOVER</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY : MESOS DNS</p><p>https://github.com/mesosphere/mesos-dns</p><p>Friday, November 27, 15</p><p>https://github.com/mesosphere/mesos-dnshttps://github.com/mesosphere/mesos-dns</p></li><li><p>MADRID NOV 27-28 2015</p><p>Build Mesos DNS Image</p><p>- Git clone : https://github.com/jmateo/mesosdns</p><p>- cd mesosdns- Edit config.json :</p><p>sed -i -e s/HOST_IP/$HOST_IP/g config.json</p><p>- Build the image :docker build -t mesosdns .</p><p>Friday, November 27, 15</p><p>https://github.com/jmateo/mesosdnshttps://github.com/jmateo/mesosdns</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY WITH MESOS DNS</p><p>1. Launch Mesos DNS container with Marathon2. Launch Mongo container3. Connect to one of the Mesos slaves and look for the mongo service (you can use dig command for doing this)4. Modify the class connection.go to connect dynamically cm-voting to mongo using service discovery (see MesosDNS REST API)</p><p>Friday, November 27, 15</p><p>http://mesosphere.github.io/mesos-dns/docs/http.htmlhttp://mesosphere.github.io/mesos-dns/docs/http.htmlhttp://mesosphere.github.io/mesos-dns/docs/http.htmlhttp://mesosphere.github.io/mesos-dns/docs/http.html</p></li><li><p>MADRID NOV 27-28 2015</p><p>LAUNCH MESOS DNS WITH MARATHONHTTP POST : http://:8080/v2/apps?force=true</p><p>Friday, November 27, 15</p><p>http://192.168.99.100:8080/v2/apps?force=truehttp://192.168.99.100:8080/v2/apps?force=true</p></li><li><p>MADRID NOV 27-28 2015</p><p>LAUNCH MESOS DNS WITH MARATHON</p><p>{ "id": "mesos-dns", "cmd": "/mesos-dns", "cpus": 0.5, "mem": 500, "container": { "type": "DOCKER", "docker": { "image": "mesosdns", "network": "HOST" } }}</p><p>Friday, November 27, 15</p></li><li><p>MADRID NOV 27-28 2015</p><p>LAUNCH MONGO CONTAINER WITH MARATHONHTTP POST : http://:8080/v2/apps?force=true</p><p>Friday, November 27, 15</p><p>http://192.168.99.100:8080/v2/apps?force=truehttp://192.168.99.100:8080/v2/apps?force=true</p></li><li><p>MADRID NOV 27-28 2015</p><p>LAUNCH MONGO CONTAINER WITH MARATHON</p><p>{ "id": "mongo", "cmd": "cat /etc/resolv.conf &gt; /tmp/temp &amp;&amp; echo \"nameserver 10.0.2.15\" &gt; /etc/resolv.conf &amp;&amp; cat /tmp/temp &gt;&gt; /etc/resolv.conf &amp;&amp; mongod", "cpus": 0.5, "mem": 500.0, "container": { "type": "DOCKER", "docker": { "image": "mongo", "privileged": true, "network": "BRIDGE", "portMappings": [ { "containerPort": 27017, "hostPort": 0 } ] } }}</p><p>HTTP POST : http://:8080/v2/apps?force=true</p><p>Friday, November 27, 15</p><p>http://192.168.99.100:8080/v2/apps?force=truehttp://192.168.99.100:8080/v2/apps?force=true</p></li><li><p>MADRID NOV 27-28 2015</p><p>LAUNCH CMVOTING WITH MARATHON{ "id": "cmvoting", "cmd": "cat /etc/resolv.conf &gt; /tmp/temp &amp;&amp; echo \"nameserver 10.0.2.15\" &gt; /etc/resolv.conf &amp;&amp; cat /tmp/temp &gt;&gt; /etc/resolv.conf &amp;&amp; revel run github.com/karesti/cm-voting prod 9000", "cpus": 0.5, "mem": 500.0, "container": { "type": "DOCKER", "docker": { "image": "cm-voting", "network": "BRIDGE", "portMappings": [ { "containerPort": 9000, "hostPort": 0 } ] } }, "env": { ! "SERVICE_NAME": "mongo" }}</p><p>HTTP POST : http://:8080/v2/apps?force=true</p><p>Friday, November 27, 15</p><p>http://192.168.99.100:8080/v2/apps?force=truehttp://192.168.99.100:8080/v2/apps?force=true</p></li><li><p>MADRID NOV 27-28 2015</p><p>SERVICE DISCOVERY WITH MESOS DNS</p><p>4. Test it :</p><p>Friday, November 27, 15</p></li></ul>