Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Introduce support for blue/green deploys.
Browse files Browse the repository at this point in the history
  • Loading branch information
brndnmtthws committed Feb 5, 2016
1 parent f87befa commit 41b9616
Show file tree
Hide file tree
Showing 17 changed files with 1,641 additions and 216 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
FROM debian
FROM debian:jessie

ENTRYPOINT [ "/marathon-lb/run" ]
CMD [ "sse", "-m", "http://master.mesos:8080", "--health-check", "--group", "external" ]
EXPOSE 80 81 443 9090

COPY . /marathon-lb

RUN apt-get update && apt-get install -y python3 python3-pip haproxy openssl runit \
RUN apt-get update && apt-get install -y python3 python3-pip openssl libssl-dev runit \
wget build-essential libpcre3 libpcre3-dev python3-dateutil socat iptables libreadline-dev \
&& pip3 install -r /marathon-lb/requirements.txt \
&& /marathon-lb/build-haproxy.sh \
&& apt-get remove -yf --auto-remove wget libssl-dev build-essential libpcre3-dev libreadline-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /marathon-lb
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ The full list of labels which can be specified are:
The group of marathon-lb instances that point to the service.
Load balancers with the group '*' will collect all groups.
HAPROXY_DEPLOYMENT_GROUP
Deployment group to which this app belongs.
HAPROXY_DEPLOYMENT_ALT_PORT
Alternate service port to be used during a blue/green deployment.
HAPROXY_DEPLOYMENT_COLOUR
Blue/green deployment colour. Used by the bluegreen_deploy.py script to determine the state of a deploy. You generally do not need to modify this unless you implement your own deployment orchestrator.
HAPROXY_DEPLOYMENT_STARTED_AT
The time at which a deployment started. You generally do not need to modify this unless you implement your own deployment orchestrator.
HAPROXY_DEPLOYMENT_TARGET_INSTANCES
The target number of app instances to seek during deployment. You generally do not need to modify this unless you implement your own deployment orchestrator.
HAPROXY_{n}_VHOST
The Marathon HTTP Virtual Host proxy hostname to gather.
Ex: HAPROXY_0_VHOST = 'marathon.mesosphere.com'
Expand Down Expand Up @@ -351,3 +366,25 @@ HAPROXY_{n}_BACKEND_SERVER_TCP_HEALTHCHECK_OPTIONS
HAPROXY_{n}_BACKEND_SERVER_HTTP_HEALTHCHECK_OPTIONS
HAPROXY_{n}_BACKEND_SERVER_OPTIONS
```

## Zero downtime deployments

Marathon-lb is able to perform canary style blue/green deployment with zero downtime. To execute such deployments, you must follow certain patterns when using Marathon.

The deployment method is described [in this Marathon document](https://mesosphere.github.io/marathon/docs/blue-green-deploy.html). Marathon-lb provides an implementation of the aforementioned deployment method with the script [`bluegreen_deploy.py`](bluegreen_deploy.py). To perform a zero downtime deploy using `bluegreen_deploy.py`, you must:


- Specify the `HAPROXY_DEPLOYMENT_GROUP` and `HAPROXY_DEPLOYMENT_ALT_PORT` labels in your app template
- `HAPROXY_DEPLOYMENT_GROUP`: This label uniquely identifies a set of apps belonging to a blue/green deployment, and will be used as the app name in the HAProxy configuration
- `HAPROXY_DEPLOYMENT_ALT_PORT`: An alternate service port is required because Marathon requires service ports to be unique across all apps
- Only use 1 service port: multiple ports are not yet implemented
- Use the provided `bluegreen_deploy.py` script to orchestrate the deploy: the script will make API calls to Marathon, and use the HAProxy stats endpoint to gracefully terminate instances
- The marathon-lb container must be run in privileged mode (to execute `iptables` commands) due to the issues outlined in the excellent blog post by the [Yelp engineering team found here](http://engineeringblog.yelp.com/2015/04/true-zero-downtime-haproxy-reloads.html)

An example minimal configuration for a [test instance of nginx is included here](tests/1-nginx.json). You might execute a deployment from a CI tool like Jenkins with:

```
./bluegreen_deploy.py -j 1-nginx.json -m http://master.mesos:8080 -f -l http://marathon-lb.marathon.mesos:9090
```

Zero downtime deployments are accomplished through the use of a Lua module, which reports the number of HAProxy processes which are currently running by hitting the stats endpoint at the `/_haproxy_getpids`. After a restart, there will be multiple HAProxy PIDs until all remaining connections have gracefully terminated. By waiting for all connections to complete, you may safely and deterministically drain tasks.
Loading

0 comments on commit 41b9616

Please sign in to comment.