Skip to content

Commit 8428bd5

Browse files
committed
feat(router): proxy builder through router
The router component is to be the point of entry for the entire Deis cluster. This commit makes the router forward connections on port 2222 to the builder. This requires manually compiling nginx from source with the tcp_proxy module and adding an appropriate upstream for builder. TESTING: rebuild the router and builder (both need to be resubmitted with fleet) ```console $ make -C router uninstall build run $ make -C builder uninstall build run ``` And focus testing in two areas: * That nothing was broken with the change to custom-built nginx (use Deis) * That the router is properly proxying git/SSH (do lots of `git push`es) closes #535
1 parent eea1f04 commit 8428bd5

8 files changed

Lines changed: 69 additions & 25 deletions

File tree

builder/bin/boot

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ done
2424
# wait until etcd has discarded potentially stale values
2525
sleep $(($ETCD_TTL+1))
2626

27-
# seed initial service configuration if necessary
28-
if ! etcdctl --no-sync -C $ETCD ls $ETCD_PATH >/dev/null 2>&1 ; then
29-
etcdctl --no-sync -C $ETCD mkdir $ETCD_PATH/users >/dev/null 2>&1 || true
30-
fi
27+
function etcd_safe_mkdir {
28+
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1 || true
29+
}
30+
31+
etcd_safe_mkdir $ETCD_PATH/users
3132

3233
# wait for confd to run once and install initial templates
3334
until confd -onetime -node $ETCD -config-file /app/confd.toml; do
@@ -72,7 +73,7 @@ echo deis-builder running...
7273
if [[ ! -z $PUBLISH ]]; then
7374

7475
# configure service discovery
75-
PORT=${PORT:-2222}
76+
PORT=${PORT:-2223}
7677
PROTO=${PROTO:-tcp}
7778

7879
set +e

builder/systemd/deis-builder.service

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ TimeoutStartSec=20m
99
ExecStartPre=/bin/sh -c "docker history deis/builder >/dev/null || docker pull deis/builder:latest"
1010
ExecStartPre=/bin/sh -c "docker inspect deis-builder >/dev/null && docker rm -f deis-builder || true"
1111
ExecStartPre=/bin/sh -c "docker inspect deis-builder-data >/dev/null 2>&1 || docker run --name deis-builder-data -v /var/lib/docker deis/base true"
12-
ExecStart=/usr/bin/docker run --name deis-builder -p 2222:22 -e PUBLISH=22 -e HOST=${COREOS_PRIVATE_IPV4} -e PORT=2222 --volumes-from deis-builder-data --privileged deis/builder
13-
ExecStartPost=/bin/sh -c "echo 'Waiting for builder on 2222/tcp...' && until cat </dev/null>/dev/tcp/$COREOS_PRIVATE_IPV4/2222; do sleep 1; done"
12+
ExecStart=/usr/bin/docker run --name deis-builder -p 2223:22 -e PUBLISH=22 -e HOST=${COREOS_PRIVATE_IPV4} -e PORT=2223 --volumes-from deis-builder-data --privileged deis/builder
13+
ExecStartPost=/bin/sh -c "echo 'Waiting for builder on 2223/tcp...' && until cat </dev/null>/dev/tcp/$COREOS_PRIVATE_IPV4/2223; do sleep 1; done"
1414
ExecStop=/usr/bin/docker rm -f deis-builder
1515

1616
[Install]

docs/operations/configure-load-balancers.rst

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@
66
Configure load balancers
77
------------------------
88

9-
For a one-node Deis cluster, there is one router and one controller, so load balancing is unnecessary. You can proceed with the next section: :ref:`configure-dns`.
9+
For a one-node Deis cluster, there is one router and one controller, so load balancing is unnecessary.
10+
You can proceed with the next section: :ref:`configure-dns`.
1011

11-
On a multi-node cluster, however, there are probably multiple routers scheduled to the cluster, and these can potentially move hosts. Therefore, it is recommended that you configure a load balancer to operate in front of the Deis cluster to serve application traffic. A simple configuration is one that has all Deis machines listed in its configuration file, but a host is only considered 'healthy' when it is serving traffic on port 80. This enables the load balancer to serve trafic to whichever hosts happen to be running the deis-router component at any one time.
12+
On a multi-node cluster, however, there are probably multiple routers scheduled to the cluster, and
13+
these can potentially move hosts. Therefore, it is recommended that you configure a load balancer
14+
to operate in front of the Deis cluster to serve application traffic. A simple configuration is one
15+
that has all Deis machines listed in its configuration file, but a host is only considered 'healthy'
16+
when it is responding to ports 80 and 2222. This enables the load balancer to serve trafic to whichever
17+
hosts happen to be running the deis-router component at any one time.
1218

13-
The load balancer is also the suggested SSL termination point, as SSL is not currently supported between Deis components.
19+
These ports need to be open on the load balancers:
1420

15-
Further documentation around load balancers is planned for Deis 1.0.
21+
* 80 (for application traffic and for API calls to the controller)
22+
* 2222 (for traffic to the builder)
23+
24+
Optionally, you can also open port 443 and configure SSL termination on the load balancers, but
25+
requests should still be forwarded to port 80 on the routers. Communication between Deis components
26+
is currently unencrypted.

router/Dockerfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
FROM deis/base
22
MAINTAINER Gabriel Monroy <gabriel@opdemand.com>
33

4-
# install nginx
5-
RUN apt-get update && \
6-
apt-get install -yq python-software-properties
7-
RUN add-apt-repository ppa:chris-lea/redis-server -y
8-
RUN add-apt-repository ppa:nginx/stable -y
94
RUN apt-get update
10-
RUN apt-get install -yq nginx
5+
RUN apt-get install -yq patch libpcre3 libpcre3-dev libssl-dev libgeoip-dev
6+
7+
RUN wget -q http://nginx.org/download/nginx-1.6.0.tar.gz -O /tmp/nginx-1.6.0.tar.gz
8+
RUN wget -q https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/v0.4.5.tar.gz -O /tmp/tcp-proxy.tar.gz
9+
10+
WORKDIR /tmp
11+
12+
RUN tar -xzf nginx-1.6.0.tar.gz
13+
RUN tar -xzf tcp-proxy.tar.gz
14+
15+
WORKDIR /tmp/nginx-1.6.0
16+
RUN patch -p1 < /tmp/nginx_tcp_proxy_module-0.4.5/tcp.patch
17+
RUN ./configure --prefix=/var/lib/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_spdy_module --with-http_sub_module --with-mail --with-mail_ssl_module --add-module=/tmp/nginx_tcp_proxy_module-0.4.5
18+
RUN make
19+
RUN make install
1120

1221
# install latest etcdctl including no-sync options
1322
RUN wget -q https://s3-us-west-2.amazonaws.com/deis/etcdctl.no-sync -O /usr/local/bin/etcdctl
1423
RUN chmod +x /usr/local/bin/etcdctl
1524

1625
ADD . /app
1726
WORKDIR /app
18-
EXPOSE 80
27+
EXPOSE 80 2222
1928
CMD ["/app/bin/boot"]

router/bin/boot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function etcd_safe_set {
3737
etcd_safe_mkdir /deis/controller
3838
etcd_safe_mkdir /deis/services
3939
etcd_safe_mkdir /deis/domains
40+
etcd_safe_mkdir /deis/builder
4041
etcd_safe_set port ${PORT:-80}
4142
etcd_safe_set gzip on
4243
etcd_safe_set gzipHttpVersion 1.0

router/conf.d/nginx.conf.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ keys = [
99
"/deis/router",
1010
"/deis/domains",
1111
"/deis/controller",
12+
"/deis/builder",
1213
]
1314
check_cmd = "/usr/sbin/nginx -t -c {{ .src }}"
1415
reload_cmd = "/usr/sbin/nginx -s reload"

router/systemd/deis-router.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ EnvironmentFile=/etc/environment
66
TimeoutStartSec=20m
77
ExecStartPre=/bin/sh -c "docker history deis/router >/dev/null || docker pull deis/router:latest"
88
ExecStartPre=/bin/sh -c "docker inspect deis-router >/dev/null && docker rm -f deis-router || true"
9-
ExecStart=/usr/bin/docker run --name deis-router -p 80:80 -e PUBLISH=80 -e HOST=${COREOS_PRIVATE_IPV4} deis/router
9+
ExecStart=/usr/bin/docker run --name deis-router -p 80:80 -p 2222:2222 -e PUBLISH=80 -e HOST=${COREOS_PRIVATE_IPV4} deis/router
1010
ExecStop=/usr/bin/docker rm -f deis-router
1111

1212
[Install]

router/templates/nginx.conf

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ http {
4949
proxy_set_header Host $host;
5050
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
5151
proxy_redirect off;
52-
proxy_connect_timeout 10;
53-
proxy_send_timeout 30;
54-
proxy_read_timeout 30;
52+
proxy_connect_timeout 10s;
53+
proxy_send_timeout 30s;
54+
proxy_read_timeout 30s;
5555

5656
proxy_pass http://deis-controller;
5757
}
@@ -75,12 +75,33 @@ http {
7575
proxy_set_header Host $host;
7676
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
7777
proxy_redirect off;
78-
proxy_connect_timeout 10;
79-
proxy_send_timeout 30;
80-
proxy_read_timeout 30;
78+
proxy_connect_timeout 10s;
79+
proxy_send_timeout 30s;
80+
proxy_read_timeout 30s;
8181

8282
proxy_pass http://{{ Base $service.Key }};
8383
}
8484
}
8585
{{ end }}{{ end }}
8686
}
87+
88+
tcp {
89+
access_log /dev/stdout;
90+
tcp_nodelay on;
91+
timeout 30000;
92+
93+
# same directive names, but these are in miliseconds...
94+
proxy_connect_timeout 10000;
95+
proxy_send_timeout 30000;
96+
proxy_read_timeout 30000;
97+
98+
upstream builder {
99+
server {{ .deis_builder_host }}:{{ .deis_builder_port }};
100+
}
101+
102+
server {
103+
listen 2222;
104+
proxy_pass builder;
105+
}
106+
}
107+

0 commit comments

Comments
 (0)