CoreOS: Control Your Fleet

Post on 08-Sep-2014

7.150 views 1 download

Tags:

description

A quick introduction into CoreOS.

Transcript of CoreOS: Control Your Fleet

CoreOSControl your fleet

@geekle

What is CoreOS?

SystemdDockerEtcdFleetCloudinit

Docker

LXC made easyPublic repositoryEasy to shareWYSIWY(M)G™

etcd

Key value store, written in goConfiguration and service discoverySimple APIRAFT Protocol (distributed consensus)Nice extras: ttl, locks

Fleet

Uses systemdExtra conditionalsRuns on etcd

Cloudinit

Subset of cloud-configCoreOS specific parametersOS agnostic

Demo

Demoish

Fetch a discovery URL

$ curl https://discovery.etcd.io/new

$ curl https://discovery.etcd.io/newhttps://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788

$ curl https://discovery.etcd.io/newhttps://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788

$ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788

$ curl https://discovery.etcd.io/newhttps://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788

$ curl https://discovery.etcd.io/cce83b966a3947533bc9e9a00b0c8788{"action":"get","node":{"key":"/_etcd/registry/cce83b966a3947533bc9e9a00b0c8788","dir":true,"modifiedIndex":5285489,"createdIndex":5285489}

Let’s create our cloud-init

#cloud-configcoreos: 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: startusers: - name: core coreos-ssh-import-github: geekle

write_files:

#cloud-configcoreos: 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: startusers: - name: core coreos-ssh-import-github: geekle

write_files:

#cloud-configcoreos: 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: startusers: - name: core coreos-ssh-import-github: geekle

write_files:

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: startusers: - name: core coreos-ssh-import-github: geekle

write_files: - path: /etc/fleet/fleet.conf

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: startusers: - name: core coreos-ssh-import-github: geekle

write_files: - path: /etc/fleet/fleet.conf content: |

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: startusers: - name: core coreos-ssh-import-github: geekle

write_files: - path: /etc/fleet/fleet.conf content: | public_ip="$private_ipv4"

addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

units: - name: etcd.service command: start - name: fleet.service command: startusers: - 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"

Boot with your favorite Paas

$ curl https://discovery.etcd.io/newhttps://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/newhttps://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

$ curl https://discovery.etcd.io/newhttps://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/24bb98332c044a1287e937c216f5d27a","value":"http://10.0.1.50:7001","expiration":"2014-04-14T11:40:57.102816593Z","ttl":604576,"modifiedIndex":5288689,"createdIndex":5288689},{"key":"/_etcd/registry/cce83b966a3947533bc9e9a00b0c8788/cf321c2c8dbc46d99236fd4a2884e353","value":"http://10.0.0.114:7001","expiration":"2014-04-14T11:44:07.598817138Z","ttl":604766,"modifiedIndex":5289124,"createdIndex":5289124},{"key":"/_etcd/registry/cce83b966a3947533bc9e9a00b0c8788/e34edaed5d8d4e589a6868daa7692fc1","value":"http://10.0.0.231:7001","expiration":"2014-04-14T11:44:14.306153655Z","ttl":604773,"modifiedIndex":5289138,"createdIndex":5289138}],"modifiedIndex":5283280,"createdIndex":5283280}}

Let’s login

$ ssh -A core@54.206.85.138

$ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ \/ ___/ / / / __ \/ ___/ _ \/ / / /\__ \/ /___/ /_/ / / / __/ /_/ /___/ /\____/\____/_/ \___/\____//____/core@ip-10-0-0-114 ~ $

$ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ \/ ___/ / / / __ \/ ___/ _ \/ / / /\__ \/ /___/ /_/ / / / __/ /_/ /___/ /\____/\____/_/ \___/\____//____/core@ip-10-0-0-114 ~ $ fleetctl list-machines

$ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ \/ ___/ / / / __ \/ ___/ _ \/ / / /\__ \/ /___/ /_/ / / / __/ /_/ /___/ /\____/\____/_/ \___/\____//____/core@ip-10-0-0-114 ~ $ fleetctl list-machinesMACHINE IP METADATA12206e61... 10.0.1.50 elastic_ip=falsebd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.13837e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131core@ip-10-0-0-114 ~ $

$ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ \/ ___/ / / / __ \/ ___/ _ \/ / / /\__ \/ /___/ /_/ / / / __/ /_/ /___/ /\____/\____/_/ \___/\____//____/core@ip-10-0-0-114 ~ $ fleetctl list-machinesMACHINE IP METADATA12206e61... 10.0.1.50 elastic_ip=falsebd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.13837e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131core@ip-10-0-0-114 ~ $ echo "\o/"

$ ssh -A core@54.206.85.138 ______ ____ _____ / ____/___ ________ / __ \/ ___/ / / / __ \/ ___/ _ \/ / / /\__ \/ /___/ /_/ / / / __/ /_/ /___/ /\____/\____/_/ \___/\____//____/core@ip-10-0-0-114 ~ $ fleetctl list-machinesMACHINE IP METADATA12206e61... 10.0.1.50 elastic_ip=falsebd57c96a... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.13837e5ec47... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.131core@ip-10-0-0-114 ~ $ echo "\o/"\o/

Let’s login remotely

$ fleetctl --tunnel '54.206.85.138' list-machines

$ fleetctl --tunnel '54.206.85.138' list-machinesMACHINE IP METADATAf7898d12... 10.0.1.50 elastic_ip=falseca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.13140e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138

$ fleetctl --tunnel '54.206.85.138' list-machinesMACHINE IP METADATAf7898d12... 10.0.1.50 elastic_ip=falseca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.13140e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138

$ fleetctl --tunnel '54.206.85.138' list-machinesMACHINE IP METADATAf7898d12... 10.0.1.50 elastic_ip=falseca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.13140e69aa8... 10.0.0.114 elastic_ip=true, public_ip=54.206.85.138$ fleetctl --tunnel '54.206.85.138' ssh f7898d12

$ fleetctl --tunnel '54.206.85.138' list-machinesMACHINE IP METADATAf7898d12... 10.0.1.50 elastic_ip=falseca1355b0... 10.0.0.231 elastic_ip=true, public_ip=54.206.52.13140e69aa8... 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 ~ $

Let’s create some services

[Unit]Description=HAProxy Service

[Service]ExecStart=/usr/bin/docker run --rm --name %n -p 80:80 -p 443:443 \-p 8080:8080 redguava/haproxy-etcdExecStop=/usr/bin/docker stop %n

[Unit]Description=Apache Service

[Service]ExecStart=/usr/bin/docker run --rm --name %n -p 80 thomaswelton/apacheExecStop=/usr/bin/docker stop %n

[X-Fleet]X-Conflicts=haproxy.service

[Unit]Description=Apache AnnounceBindsTo=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

Let’s add the services

$ fleetctl --tunnel '54.206.85.138' submit *.service$ fleetctl --tunnel '54.206.85.138' list-unitsUNIT LOADACTIVE SUB DESC MACHINEapache-announce.service - - - Apache Announce -apache.service - - - Apache Service -haproxy.service - - - HAProxy Service -

$ fleetctl --tunnel '54.206.85.138' start --require 'elastic_ip=true' haproxy.service$ fleetctl --tunnel '54.206.85.138' list-unitsUNIT LOADACTIVE SUB DESC MACHINEapache-announce.service - - - Apache Announce -apache.service - - - Apache Service -haproxy.service loaded active running HAProxy Service ca1355b0.../10.0.0.231

$ fleetctl --tunnel '54.206.85.138' start apache*.service$ fleetctl --tunnel '54.206.85.138' list-unitsUNIT LOADACTIVE SUB DESC MACHINEapache-announce.service loaded active running Apache Announcef7898d12.../10.0.1.50apache.service loaded active running Apache Service f7898d12.../10.0.1.50haproxy.service loaded active running HAProxy Service ca1355b0.../10.0.0.231

core@ip-10-0-1-50 ~ $ etcdctl ls --recursive/services/services/web/services/web/ip-10-0-1-50core@ip-10-0-1-50 ~ $ etcdctl get /services/web/ip-10-0-1-50{ "host": "10.0.1.50", "port": "49154" }

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.