Load balancing with NGINX


core-01

$ fleetctl list-units
UNIT				MACHINE				ACTIVE	SUB
[email protected]	3408f7ab.../172.17.8.103	active	running
[email protected]	b2ca4512.../172.17.8.101	active	running
[email protected]		3408f7ab.../172.17.8.103	active	running
[email protected]		b2ca4512.../172.17.8.101	active	running
[email protected]		3408f7ab.../172.17.8.103	active	running
[email protected]		db577263.../172.17.8.102	active	running
[email protected]		b2ca4512.../172.17.8.101	active	running
[email protected]			3408f7ab.../172.17.8.103	active	running
[email protected]			db577263.../172.17.8.102	active	running
[email protected]			b2ca4512.../172.17.8.101	active	running


Я заменил оригинальные image, своими. Они отличаются пока только IP адресом. С оригинальным у меня не заработало.


$ vi nginx.service


[Unit]
Description=Nginx Proxy

Requires=docker.service
After=docker.service
After=etcd2.service
Requires=etcd2.service

[Service]
EnvironmentFile=/etc/environment
User=core

Restart=always
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStartPre=-/usr/bin/etcdctl mkdir /services/todo
ExecStartPre=-/usr/bin/docker pull marley/coreos-nginx-proxy
ExecStart=/usr/bin/docker run --name %p-%i \
 -h %H \
 -p \${COREOS_PUBLIC_IP}:80:80 \
 marley/coreos-nginx-proxy
ExecStop=-/usr/bin/docker kill %p-%i
ExecStop=-/usr/bin/docker rm %p-%i

[X-Fleet]
Global=true


$ fleetctl submit nginx.service
$ fleetctl start nginx.service


$ fleetctl list-units
UNIT				MACHINE				ACTIVE	SUB
nginx.service			3408f7ab.../172.17.8.103	active	running
nginx.service			b2ca4512.../172.17.8.101	active	running
nginx.service			db577263.../172.17.8.102	active	running
[email protected]	3408f7ab.../172.17.8.103	active	running
[email protected]	b2ca4512.../172.17.8.101	active	running
[email protected]		3408f7ab.../172.17.8.103	active	running
[email protected]		b2ca4512.../172.17.8.101	active	running
[email protected]		3408f7ab.../172.17.8.103	active	running
[email protected]		db577263.../172.17.8.102	active	running
[email protected]		b2ca4512.../172.17.8.101	active	running
[email protected]			3408f7ab.../172.17.8.103	active	running
[email protected]			db577263.../172.17.8.102	active	running
[email protected]			b2ca4512.../172.17.8.101	active	running


// логи

$ journalctl -f --lines -u nginx


http://172.17.8.101/
http://172.17.8.102/
http://172.17.8.103/

Тоже самое, только на 80 порту а не на 3000

coreos cluster

Если нужно остановить и выгрузить все, что касается сервиса:

$ fleetctl stop nginx.service
$ fleetctl unload nginx.service
$ fleetctl destroy nginx.service