CoreOS: Control Your Fleet

14,936 views

Published on

A quick introduction into CoreOS.

Published in: Technology
2 Comments
45 Likes
Statistics
Notes
No Downloads
Views
Total views
14,936
On SlideShare
0
From Embeds
0
Number of Embeds
411
Actions
Shares
0
Downloads
256
Comments
2
Likes
45
Embeds 0
No embeds

No notes for slide

CoreOS: Control Your Fleet

  1. 1. CoreOS Control your fleet @geekle
  2. 2. What is CoreOS? Systemd Docker Etcd Fleet Cloudinit
  3. 3. Docker LXC made easy Public repository Easy to share WYSIWY(M)G™
  4. 4. etcd Key value store, written in go Configuration and service discovery Simple API RAFT Protocol (distributed consensus) Nice extras: ttl, locks
  5. 5. Fleet Uses systemd Extra conditionals Runs on etcd
  6. 6. Cloudinit Subset of cloud-config CoreOS specific parameters OS agnostic
  7. 7. Demo
  8. 8. Demoish
  9. 9. Fetch a discovery URL
  10. 10. $ curl https://discovery.etcd.io/new
  11. 11. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788
  12. 12. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788
  13. 13. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 {"action":"get","node":{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true," modifiedIndex":5285489,"createdIndex":5285489}
  14. 14. Let’s create our cloud-init
  15. 15. #cloud-config coreos: etcd: discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files:
  16. 16. #cloud-config coreos: etcd: discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files:
  17. 17. #cloud-config coreos: etcd: discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files:
  18. 18. coreos: etcd: discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf
  19. 19. etcd: discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: |
  20. 20. discovery: https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4"
  21. 21. addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  22. 22. peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  23. 23. units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  24. 24. units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  25. 25. units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  26. 26. units: - name: etcd.service command: start - name: fleet.service command: start users: - name: core coreos-ssh-import-github: geekle write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4" metadata="elastic_ip=true,public_ip=$public_ipv4"
  27. 27. Boot with your favorite Paas
  28. 28. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 {"action":"get","node":{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true," modifiedIndex":5285489,"createdIndex":5285489}
  29. 29. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 {"action":"get","node":{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true," modifiedIndex":5285489,"createdIndex":5285489} $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788
  30. 30. $ curl https://discovery.etcd.io/new https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 {"action":"get","node":{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true," modifiedIndex":5285489,"createdIndex":5285489} $ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788 {"action":"get","node":{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true,"nodes": [{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788/24bb98332c044a1287e937c216 f5d27a","value":"http://10.0.1.50:7001","expiration":"2014-04-14T11:40: 57.102816593Z","ttl":604576,"modifiedIndex":5288689,"createdIndex": 5288689},{"key":" /_etcd/registry/cce83b966a3947533bc9e9a00b0c8788/cf321c2c8dbc46d99236fd4a28 84e353","value":"http://10.0.0.114:7001","expiration":"2014-04-14T11:44: 07.598817138Z","ttl":604766,"modifiedIndex":5289124,"createdIndex": 5289124},{"key":"
  31. 31. Let’s login
  32. 32. $ ssh -A core@54.206.85.138
  33. 33. $ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-0-114 ~ $
  34. 34. $ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-0-114 ~ $ fleetctl list-machines
  35. 35. $ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-0-114 ~ $ fleetctl list-machines MACHINE IP METADATA 12206e61... 10.0.1.50 elastic_ip=false bd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138 37e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 core@ip-10-0-0-114 ~ $
  36. 36. $ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-0-114 ~ $ fleetctl list-machines MACHINE IP METADATA 12206e61... 10.0.1.50 elastic_ip=false bd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138 37e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 core@ip-10-0-0-114 ~ $ echo "o/"
  37. 37. $ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-0-114 ~ $ fleetctl list-machines MACHINE IP METADATA 12206e61... 10.0.1.50 elastic_ip=false bd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138 37e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 core@ip-10-0-0-114 ~ $ echo "o/" o/
  38. 38. Let’s login remotely
  39. 39. $ fleetctl --tunnel '54.206.85.138' list-machines
  40. 40. $ fleetctl --tunnel '54.206.85.138' list-machines MACHINE IP METADATA f7898d12... 10.0.1.50 elastic_ip=false ca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 40e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138
  41. 41. $ fleetctl --tunnel '54.206.85.138' list-machines MACHINE IP METADATA f7898d12... 10.0.1.50 elastic_ip=false ca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 40e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138
  42. 42. $ fleetctl --tunnel '54.206.85.138' list-machines MACHINE IP METADATA f7898d12... 10.0.1.50 elastic_ip=false ca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 40e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138 $ fleetctl --tunnel '54.206.85.138' ssh f7898d12
  43. 43. $ fleetctl --tunnel '54.206.85.138' list-machines MACHINE IP METADATA f7898d12... 10.0.1.50 elastic_ip=false ca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131 40e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138 $ fleetctl --tunnel '54.206.85.138' ssh f7898d12 ______ ____ _____ / ____/___ ________ / __ / ___/ / / / __ / ___/ _ / / / /__ / /___/ /_/ / / / __/ /_/ /___/ / ____/____/_/ ___/____//____/ core@ip-10-0-1-50 ~ $
  44. 44. Let’s create some services
  45. 45. [Unit] Description=HAProxy Service [Service] ExecStart=/usr/bin/docker run --rm --name %n -p 80:80 -p 443:443 -p 8080:8080 redguava/haproxy-etcd ExecStop=/usr/bin/docker stop %n
  46. 46. [Unit] Description=Apache Service [Service] ExecStart=/usr/bin/docker run --rm --name %n -p 80 thomaswelton/apache ExecStop=/usr/bin/docker stop %n [X-Fleet] X-Conflicts=haproxy.service
  47. 47. [Unit] Description=Apache Announce BindsTo=apache.service [Service] ExecStart=/bin/bash -c "HOST_IP=$(/bin/ifconfig eth0 | awk '/inet /{print $2}') && CONTAINER_PORT=$(docker inspect apache.service | grep -m 1 HostPort | tr -d ' ' | cut -d: -f2 | tr -d '"') && while true; do etcdctl set /services/web/%H "{ "host": "$HOST_IP", "port": "$CONTAINER_PORT" }" --ttl 60;sleep 45;done" ExecStop=/usr/bin/etcdctl rm /services/web/%H [X-Fleet] X-ConditionMachineOf=apache.service
  48. 48. Let’s add the services
  49. 49. $ fleetctl --tunnel '54.206.85.138' submit *.service $ fleetctl --tunnel '54.206.85.138' list-units UNIT LOAD ACTIVE SUB DESC MACHINE apache-announce.service - - - Apache Announce - apache.service - - - Apache Service - haproxy.service - - - HAProxy Service -
  50. 50. $ fleetctl --tunnel '54.206.85.138' start --require 'elastic_ip=true' haproxy.service $ fleetctl --tunnel '54.206.85.138' list-units UNIT LOAD ACTIVE SUB DESC MACHINE apache-announce.service - - - Apache Announce - apache.service - - - Apache Service - haproxy.service loaded active running HAProxy Service ca1355b0... /10.0.0.231
  51. 51. $ fleetctl --tunnel '54.206.85.138' start apache*.service $ fleetctl --tunnel '54.206.85.138' list-units UNIT LOAD ACTIVE SUB DESC MACHINE apache-announce.service loaded active running Apache Announce f7898d12.../10.0.1.50 apache.service loaded active running Apache Service f7898d12... /10.0.1.50 haproxy.service loaded active running HAProxy Service ca1355b0... /10.0.0.231
  52. 52. core@ip-10-0-1-50 ~ $ etcdctl ls --recursive /services /services/web /services/web/ip-10-0-1-50 core@ip-10-0-1-50 ~ $ etcdctl get /services/web/ip-10-0-1-50 { "host": "10.0.1.50", "port": "49154" }
  53. 53. Things You Should Know - discovery.etcd.io has a 1 week TTL - It is in alpha. Beta on the way. - Automatic restarts after updates during the alpha. You can disable this.

×