Project: Chef Habitat (App Definition and Development / Application Definition & Image Build)
File: mesos_dcos.md

+++ title = "Apache Mesos and DC/OS" description = "Apache Mesos and DC/OS" gh_repo = "habitat" [menu] [menu.habitat] title = "Apache Mesos and DC/OS" identifier = "habitat/containers/mesos-dcos" parent = "habitat/containers" weight = 70 +++ is an open source distributed systems kernel and the distributed systems kernel for distributed platform. Mesos has support for for running commands and applications within isolated containers. Mesos supports Docker and its own format. The Mesos containerizer provides lightweight containerization with `cgroups/namespaces` isolation without actual isolation. The `hab pkg export mesos` command creates a mostly empty base filesystem with the application and the Chef Habitat Supervisor and packages it into a compressed tarball. is a container orchestration platform for Mesos and DC/OS, handling the scheduling and deployment of applications. support Docker and the Mesos container formats, wrapping them in JSON metadata describing the resources needed to deploy the application. Once the application has been deployed to Marathon, it schedules it across the Mesos cluster and ensures the application is running optimally. You can create native Mesos containers from Chef Habitat packages by following these steps: Create an interactive studio in any directory with the `hab studio enter` command. Install or the Chef Habitat package from which you want to create a Marathon application, for example: ```bash $ hab pkg install yourorigin/yourpackage ``` Run the Mesos exporter on the package. ```bash $ hab pkg export mesos yourorigin/yourpackage ``` This will create a Mesos container-format tarball in the results directory, and also print the JSON needed to load the application into Marathon. Note that the tarball needs to be uploaded to a download location and the `"uris"` in the JSON need to be updated manually. This is an example of the output: ```json { "id": "yourorigin/yourpackage", "cmd": "/bin/id -u hab &>/dev/null || /sbin/useradd hab; /bin/chown -R hab:hab *; mount -t proc proc proc/; mount -t sysfs sys sys/;mount -o bind /dev dev/; /usr/sbin/chroot . ./init.sh start yourorigin/yourpackage", "cpus": 0.5, "disk": 0, "mem": 256, "instances": 1, "uris": [ "https://storage.googleapis.com/mesos-habitat/yourorigin/yourpackage-0.0.1-20160611121519.tgz" ] } ``` Note that the default resource allocation for the application is very small: 0.5 units of CPU, no disk, one instance, and 256MB of memory. To change these resource allocations, pass different values to the Mesos exporter as command line options (defaults are documented with `--help`). From the DC/OS web interface, launch the Marathon Service. Select "Create Application". Click on the "JSON Mode" selector and enter the JSON output of the Mesos exporter and click "Create Application". Marathon will then deploy the application and enter the "Running" status. You can get to the output from the running application by clicking on the "Marathon" service from the DC/OS "Services" tab. Select the application and the "Log Viewer" and choose either the "Error" or "Output" to see `stderr` and `stdout` respectively. If you have SSH access into the nodes, the Mesos container directories are beneath `/var/lib/mesos/slave/slaves`. This is a basic integration, there are many improvements yet to be made. Here are a few examples: Marathon environment variables are not passed into the Chef Habitat package "cmd" yet. Networking ports exposed by Chef Habitat need to be added to the JSON. The Chef Habitat gossip protocol needs to be included as a default exposed port. If Marathon is running the , support uploading the tarball directly into it. Upload applications directly to the . Marathon supports unpacking several archive formats. Native `.hart` support could be added directly to Marathon.