Search code examples
bosh-deployercf-bosh

Is job affinity possible with BOSH?


Say I want to deploy Mesos. Mesos has a dependency on Zookeeper. How can I create an affinity between the two jobs with BOSH.

Ideally I would be able to have my Mesos job spin up and know which instance of Zookeeper it should be talking to and how to do so. They should also run on the same VM.


Solution

  • Yes, in you deployment manifest you can determine which jobs are colocated with others on VMs

    jobs:
      - name: mesos_master
        templates:
          - name: mesos
            release: mesos-release
          - name: zookeeper
            release: zookeeper-release
        ...
    

    There is some unfortunate naming here that is worth clarifying. A release is basically your collection of source code, vendored binaries, and templates for your processes' startup scripts and config files. Each release has many jobs, where a job essentially consists of pointers to packages (compiled source and vendored binaries) and templates that get rendered at runtime to determine the startup scripts and config files for the processes encapsulated in a job. Most jobs encapsulate a single process (e.g. an etcd job would probably just encapsulate the packages, startup scripts, and config files for an etcd server daemon).

    A deployment manifest also has many jobs, and each of those jobs has many templates. However, the templates in a deployment job refer to jobs in a release. These names will change in the future to be unambiguous, but it's something to keep in mind about the current nomenclature. It used to be the case that each deployment job could only have one release job defined for it, so it was simply:

    jobs:
      - name: mesos
        release: mesos-release
    

    so there was no ambiguity, but also no ability to have affinity of multiple different release jobs in a single deployment job.

    Not sure which docs you found that weren't useful, perhaps it's these ones, but in case you missed them:

    Here is also an example manifest that's not too big and not too small. You'll see it has a few jobs, some of which only have one "template" (a.k.a. release job), and some of which have 2 or 3.