关注微信公众号
第一手干货与资讯
加入官方微信群
获取免费技术支持
*This post is now a bit out of date. Since posting this article we’ve added full support for Mesos environments directly into Rancher. You can read more about it at rancher.com/mesos. * Hi, I’m Sidhartha Mani, one of the engineers here at Rancher Labs. Over the last few months I’ve been working with Apache Mesos, an open source resource manager and scheduler, which can be used to deploy workloads on infrastructure. Mesos is very good at understanding resources and capacity management, but for more advanced workload or container management, many users choose a framework such as Marathon. Frameworks provide capabilities like load balancing, service discovery, rolling upgrades, application composability, continuous deployment and others. A number of Rancher’s community members who are also using Mesos have felt the need for a system that combines the fault tolerance, and scheduling capabilities of Mesos with the multi-tenant, private container service capabilities provided by Rancher. One community user, Marcel Neuhausler from AT&T Foundry, took the initiative to chart a broad design and envisioned a workflow for such an integration. He had a very interesting insight to combine Mesos’ ability to schedule VMs with Rancher’s ability to then manage those VMs and deploy containers on them. He wrote a Mesos framework for Rancher on Mesos, which proved to be a great starting point for writing the framework I’m going to talk about today. In this blog, I am going to describe the ideas and the software - Rancher Mesos framework, that resulted through the act of collaboration with Marcel. This framework can be used to setup large scale production jobs like Hadoop, Kafka, ElasticSearch etc. in docker containers, as well as any part of the DevOps pipeline, such as build, test, staging or production application environments. In the sections below, I’ll discuss the architecture of the framework, and show you how to set it up on your local environment.
Here’s a diagram explaining the Rancher Mesos Framework As you can see, Rancher integrates with Mesos using standard Mesos interfaces - A Mesos framework. The various components are
mesos-master
rancher/server
rancher/agent
create host
resource offers
The user’s point of view of working with the Rancher Mesos framework would be no different from using Rancher today.
Add Host
This picture explains the sequence of events to provision a host using Rancher Mesos
physicalhost.create
In this section, I’ll show you how to setup this architecture on your laptop to try it out. We’ll use VMware fusion pro to virtualize the setup as it requires changing networking configuration, and its easier to work this way. Download the iso for Ubuntu Desktop 14.04.2. In VMware fusion, select Add > Install from disk or image. Make sure you enable nested virtualization, and have at least 2GB of Memory before booting. To enable nested virtualization
Add > Install from disk or image
Click on settings > Processors and Memory > Advanced Options > Enable Hypervisor Applications
Now boot it up.
The first step in setting up is network configuration. We need to setup bridge networking for eth0. Before continuing, ensure that bridge-utils is installed, usingsudo apt-get install bridge-utils. Setup your /etc/network/interfaces as follows :-
eth0
bridge-utils
sudo apt-get install bridge-utils
/etc/network/interfaces
auto lo iface lo inet loopback auto eth0 iface eth0 inet manual auto br0 iface br0 inet dhcp bridge_ports eth0 bridge_stp off bridge_fd 0 bridge_maxwait 0
Then run ifup -a, which reads the config file and sets up the bridge interface. If you run ifconfig now, you’ll notice there is no IP address on eth0, and there is a br0interface with a configured IP address. From here onwards, when I refer to $IP, it is the IP address on br0 on this machine
ifup -a
ifconfig
br0
$IP
The next step is installing the necessary packages. First, you’ll need gitsudo apt-get install gitTo install QEMU-KVM, use this command,
sudo apt-get install git
sudo apt-get install -y qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils echo 'allow br0' > /etc/qemu/bridge.conf
Then, install the executor (You need golang, mercurial , and Godeps)
go get -d github.com/wlan0/rancher-mesos-executor cd $GOPATH/src/github.com/wlan0/rancher-mesos-executor && ./scripts/build sudo cp build/rancher-mesos-executor /bin/
Then replace executor with scheduler in the previous steps to install rancher-mesos-scheduler. Finally, install docker
wget -qO- https://get.docker.com | sh
Start rancher-server
sudo docker run -p 8080:8080 -d wlan0/rancher-server
This will start rancher-server on port 8080
Install Mesos master and slave
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF echo "deb http://repos.mesosphere.io/ubuntu/ trusty main" > /etc/apt/sources.list.d/mesosphere.list sudo apt-get -y update sudo apt-get -y install mesos service zookeeper stop sudo apt-get -y remove --purge zookeeper echo manual > /etc/init/mesos-master.override
Start Mesos master and slave
sudo nohup mesos-master --work_dir=$(pwd) --ip=$IP & sudo nohup mesos-slave --master=$IP:5050 --ip=$IP &
Start the rancher-mesos scheduler.
CATTLE_URL=http://$IP:8080/v1 CATTLE_ACCESS_KEY=service CATTLE_SECRET_KEY=servicepass MESOS_MASTER=$IP:5050 IP_CIDR=$IP/24 rancher-mesos-scheduler
Now from a browser, go to $IP:8080 to see the Rancher UI. Now, I had to do a bit of a hack to get the UI to call to mesos, as Rancher uses Docker Machine for adding resources from clouds, and I haven’t had time to create a custom Mesos machine driver. So, to add a host, click on add host within any environment and select the \“Rackspace\” icon, use any dummy credentials, and hit create. You should see a host get added to the Infrastructure tab of Rancher. Wait for a few minutes for the host to connect to cattle. Once it does, you’ll be able to use this host to start containers. Note: I have short circuited the authentication part in the external handler(rancher-mesos-scheduler) to ignore the cloud type and always provision Mesos hosts, so this will work from any of the different cloud drivers or from the Rancher API. In the future I’ll add a proper Mesos driver for the create host function.
$IP:8080
Note that everytime you provision a host, the console for the created VM will pop up on your screen. This can be disabled for production environments.
Hopefully this gives you an idea of how to deploy Rancher as a framework on Mesos. Thanks again to Marcel from AT&T Foundry for workign with our team on this, and all the other community members who have attempted or suggested this integration. With Rancher on Mesos, creating a multi-tenant private container service, on top of your Mesos cluster.
Also, If you’d like help setting up your environment please join our Rancher beta program, request a demo, or register for our next online meetup.