[O’Reilly Media / Infinite Skills] Introduction to CoreOS Training Video [2015, ENG] : Deploying A DatabaseBacked Web Application : Deploying Web Application

Deploying Web Application

core-01

$ fleetctl list-machines
MACHINE		IP		METADATA
3408f7ab...	172.17.8.103	-
b2ca4512...	172.17.8.101	-
db577263...	172.17.8.102	-


$ 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


$ etcdctl get /services/rethinkdb/rethinkdb-1
172.17.8.103

$ etcdctl get /services/rethinkdb/rethinkdb-2
172.17.8.101


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


$ vi [email protected]

[Unit]
Description=ToDo Service

Requires=docker.service
[email protected]%i.service
After=docker.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/docker pull marley/coreos-todo-angular-express
ExecStart=/usr/bin/docker run --name %p-%i \
      -h %H \
      -p ${COREOS_PUBLIC_IPV4}:3000:3000 \
      -e INSTANCE=%p-%i \
      marley/coreos-todo-angular-express
ExecStop=-/usr/bin/docker kill %p-%i
ExecStop=-/usr/bin/docker rm %p-%i

[X-Fleet]
[email protected]*.service


$ vi [email protected]

[Unit]
Description=ToDo Sidekick
[email protected]%i.service

After=docker.service
[email protected]%i.service
[email protected]%i.service

[Service]
EnvironmentFile=/etc/environment
User=core
Restart=always
TimeoutStartSec=0
ExecStart=/bin/bash -c '\
while true; do \
 port=$(docker inspect --format=\'\' todo-%i); \
 curl -sf ${COREOS_PUBLIC_IPV4}:$port/ > /dev/null 2>&1; \
 if [ $? -eq 0 ]; then \
   etcdctl set /services/todo/todo-%i ${COREOS_PUBLIC_IPV4}:$port --ttl 10; \
 else \
   etcdctl rm /services/todo/todo-%i; \
 fi; \
 sleep 5; \
 done'

ExecStop=/usr/bin/etcdctl rm /services/todo/todo-%i

[X-Fleet]
[email protected]%i.service


$ fleetctl submit todo*


$ fleetctl start [email protected]{1..3} [email protected]{1..3}


$ 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]		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
[email protected]			3408f7ab.../172.17.8.103	active	running


$ fleetctl journal -f --lines=50 [email protected]
$ fleetctl journal -f --lines=50 [email protected]


$ etcdctl ls --recursive
/test
/test/hello
/services
/services/rethinkdb
/services/rethinkdb/rethinkdb-1
/services/rethinkdb/rethinkdb-2
/services/todo
/services/todo/todo-2
/services/todo/todo-1
/services/todo/todo-3
/coreos.com
/coreos.com/network
/coreos.com/network/config
/coreos.com/network/subnets
/coreos.com/network/subnets/10.1.99.0-24
/coreos.com/network/subnets/10.1.34.0-24
/coreos.com/network/subnets/10.1.29.0-24
/coreos.com/updateengine
/coreos.com/updateengine/rebootlock
/coreos.com/updateengine/rebootlock/semaphore
/foo
/foo/bar
/foo/bar2


$ etcdctl get /services/todo/todo-3
172.17.8.101:3000


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


coreos cluster


Если нужно все остановить и почистить:

$ fleetctl stop [email protected]{1..3} [email protected]{1..3}
$ fleetctl unload [email protected]{1..3} [email protected]{1..3}

$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]

$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]
$ fleetctl destroy [email protected]