Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/addressable ips #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

csconnell
Copy link

These changes provide a way to update the HAProxy config for docker containers that are on addressable IPs (i.e IP addresses reachable on the network / outside of the local docker host). The change allows you to provide a discovery setting of "addressable_ip" for docker discovered services as shown below:

"services": {
    "local-nodes": {
      "discovery": {
        "method": "docker",
        "addressable_ip": "true",
        "servers": [
          {
            "name": "localhost",
            "host": "192.168.224.2",
            "port": 4243
          }
    ],
    "container_port": 8000,
        "image_name": "local/testapp"
      },
      "haproxy": {
        "port": 9091,
      }

This change then looks up the actual IP address of the docker container instead of using the docker host and then uses the private port of the service. The change does not affect the previous functionality - both services with non-addressable IPs and those with addressable IPs are properly written to the HAProxy config. So a synapse config file that looks like this:

{
  "services": {
    "local-nodes": {
      "discovery": {
        "method": "docker",
        "addressable_ip": "true",
        "servers": [
          {
            "name": "localhost",
            "host": "192.168.224.2",
            "port": 4243
          }
    ],
    "container_port": 8000,
        "image_name": "local/testapp"
      },
      "haproxy": {
        "port": 9091,

      }

    },
    "remote-nodes":{
      "discovery": {
        "method": "docker",
        "servers": [
          {
            "name": "cconnell3",
            "host": "192.168.222.153",
        "port": 4243
      }
        ],
      "container_port": 8000,
        "image_name": "local/testapp"
      },
      "haproxy": {
        "port": 9091,

      }

    },
    "proxy-clients": {
      "discovery": {
        "method": "docker",
        "addressable_ip": "true",
        "servers": [
          {
            "name": "localhost",
            "host": "192.168.224.2",
            "port": 4243
      }
        ],
        "container_port": 9090,
        "image_name": "local/proxy-node"
      },
      "haproxy": {
        "port": 9090,

      }

    },

  },
"haproxy": {
    "reload_command": "systemctl reload haproxy.service",
    "config_file_path": "/etc/haproxy/haproxy.cfg",
    "do_writes": true,
    "do_reloads": true,
    "bind_address": "*",
    "global": [
      "daemon",
      "maxconn 4096",
    ],
    "defaults": [
      "maxconn  2000",
      "timeout  connect 5s",
      "timeout  client  1m",
      "timeout  server  1m",
      "mode http",
    ],
  }
}

will result in an haproxy config like:

# auto-generated by synapse at 2014-09-03 16:04:10 -0400

global
        daemon
    maxconn 4096
defaults
        maxconn  2000
        timeout  connect 5s
        timeout  client  1m
        timeout  server  1m
        mode http

frontend local-nodes
        bind *:9091
        default_backend local-nodes

backend local-nodes
        server 192.168.224.19:8000_27f8db643d74 192.168.224.19:8000 cookie 192.168.224.19:8000_27f8db643d74
        server 192.168.224.22:8000_c5dd48c1adac 192.168.224.22:8000 cookie 192.168.224.22:8000_c5dd48c1adac
        server 192.168.224.18:8000_df6616b4e4af 192.168.224.18:8000 cookie 192.168.224.18:8000_df6616b4e4af

frontend remote-nodes
        bind *:9091
        default_backend remote-nodes

backend remote-nodes
        server 192.168.222.153:49155_cconnell3 192.168.222.153:49155 cookie 192.168.222.153:49155_cconnell3
        server 192.168.222.153:49154_cconnell3 192.168.222.153:49154 cookie 192.168.222.153:49154_cconnell3
        server 192.168.222.153:49153_cconnell3 192.168.222.153:49153 cookie 192.168.222.153:49153_cconnell3

frontend proxy-clients
        bind *:9090
        default_backend proxy-clients

backend proxy-clients
        server 192.168.224.28:9090_sel-node-6 192.168.224.28:9090 cookie 192.168.224.28:9090_sel-node-6
        server 192.168.224.29:9090_sel-node-7 192.168.224.29:9090 cookie 192.168.224.29:9090_sel-node-7
        server 192.168.224.25:9090_sel-node-4 192.168.224.25:9090 cookie 192.168.224.25:9090_sel-node-4
        server 192.168.224.30:9090_sel-node-8 192.168.224.30:9090 cookie 192.168.224.30:9090_sel-node-8
        server 192.168.224.24:9090_sel-node-3 192.168.224.24:9090 cookie 192.168.224.24:9090_sel-node-3
        server 192.168.224.27:9090_sel-node-5 192.168.224.27:9090 cookie 192.168.224.27:9090_sel-node-5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant