#Nginx Load Balancer Service For Core OS
Create a directory to manage using fleetctl for this service:
$ mkdir static
Create this file in static/nginx_lb.service
[Unit]
Description=Nginx load balancer for web server backends
# Requirements
Requires=etcd.service
Requires=docker.service
# Dependency ordering
After=etcd.service
After=docker.service
[Service]
# Let the process take awhile to start up (for first run Docker containers)
TimeoutStartSec=0
# Change killmode from "control-group" to "none" to let Docker remove
# work correctly.
KillMode=none
# Get CoreOS environmental variables
EnvironmentFile=/etc/environment
# Pre-start and Start
## Directives with "=-" are allowed to fail without consequence
ExecStartPre=-/usr/bin/docker kill nginx_lb
ExecStartPre=-/usr/bin/docker rm nginx_lb
ExecStartPre=/usr/bin/docker pull mssio/nginx_lb_node
ExecStart=/usr/bin/docker run --name nginx_lb -p ${COREOS_PUBLIC_IPV4}:80:80 \
mssio/nginx_lb_node /usr/local/bin/confd-watch
# Stop
ExecStop=/usr/bin/docker stop nginx_lb
[X-Fleet]
X-Conflicts=nginx.service
X-Conflicts=node@*.service
Finally just run this command from shell and you Load Balancer should be up and run perfectly
$ fleetctl start instances/*
PS:
- You should change mssio/nginx_lb_node with your own node application image
- Based on tutorial in Digital Ocean