QubitProducts / bamboo

HAProxy auto configuration and auto service discovery for Mesos Marathon
Apache License 2.0
793 stars 214 forks source link

Setting Docker Network to Host Breaks HAProxy #171

Closed scottbrumley closed 8 years ago

scottbrumley commented 8 years ago

When I try to spin up an app in marathon with the network set to HOST it breaks the proxy. Is there a way to tell bamboo the static ports for a backend app?

Thanks, Scott

lclarkmichalek commented 8 years ago

You could probably transfer the information in a label, and the use that in the template. Can you give more details on what template you are using, and exactly how the proxy breaks with it?

scottbrumley commented 8 years ago

Thanks for the quick response. It appears to be more of an issue with how marathon reports the ports than bamboo. In marathon when we run an app, if we use "network":"HOST" instead of "network":"BRIDGE" for our docker containers then bamboo can only give Haproxy the servicePort information since HOST for docker is not NATed (and doesn't actually have portParameters). I was hoping there might be a trick to allow a static port for an apps while maintaining dynamic servers.

For configs I'm using the default template that come in the git package (haproxy_template.cfg, production.example.json). It's worked so well I haven't had to dive into building anything custom yet. A label is an interesting idea. So it would be something like if network = HOST then use label information in place of {{task.port}}. Do you have any examples of specific syntax?

Scott

lclarkmichalek commented 8 years ago

We have tried (using environment variables, not labels, due to a old docker version), to pass an arbitrary port using

{{ range $index, $app := .Apps }} {{ if $app.Env.BAMBOO_TCP_PORT }}
listen {{ $app.EscapedId }}-cluster-tcp :{{ $app.Env.BAMBOO_TCP_PORT }}
    mode tcp
    option tcplog
    balance roundrobin

    {{ range $page, $task := .Tasks }}
    server {{ $app.EscapedId}}-{{ $task.Host }}-{{ $task.Env.BAMBOO_TCP_PORT}} {{ $task.Host }}:{{ $task.Env.BAMBOO_TCP_PORT }}  {{ end }}
{{ end }}
{{ end }}

You could do something similar, using labels. Note that this example was used with containers running behind a NAT'd bridge, so you may still encounter problems if marathon refuses to process non NAT'd containers, but it should show the basic idea of how you can get around a lack of information in the marathon task defn. I have no real experience with non NAT'd containers, so there may be a better way, but this is what comes to mind immediately.

j1n6 commented 8 years ago

With the default template, it has a environment variable used BAMBOO_TCP_PORT. You can custom set a port for the service to be load-balanced.

Here's the documentation: https://github.com/QubitProducts/bamboo#customize-haproxy-template-with-marathon-app-environment-variables

scottbrumley commented 8 years ago

Ok maybe I'm totally a goof. I can't get it to pull the BAMBOO_TCP_PORT. It shows it has no value. I'm not sure what the syntax would be for labels. $app.label or something?

scottbrumley commented 8 years ago

Looks like I have something working.