Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DockerGrunn 20150303 - Docker Clustering en Service Discovery met CoreOS

DockerGrunn 20150303 - Docker Clustering en Service Discovery met CoreOS

Presentatie tijdens DockerGrunn meetup van 3 maart 2015.

Marcel Harkema

March 03, 2015
Tweet

Other Decks in Programming

Transcript

  1. Boodschappenlijstje • Packaging"van"de"services"met"a.ankelijkheden • Deployment"van"de"services • Plek"om"ze"te"laten"landen • Meervoudig"vanwege"beschikbaarheid •

    Nieuwe"versie"neerze<en"terwijl"de"winkel"openblij> • Service3discovery:"Ontdekken"waar"de"services"draaien • Load"balancing • Health"checks"(niet"gezonde"services"uit"de"roulaDe"nemen) • Service3registry:"Plek"om"vast"te"leggen"welke"services"waar"draaien • Service3announcement:"Service"maakt"zich"bekend"aan"de"omgeving
  2. OS#voor#containers:#CoreOS • Minimaal(Linux(OS(gemaakt(voor( containers((Docker,(systemd<nspawn,( Rocket) • "Secure(the(internet" • Atomic(automaDc(updates((acDve/ passive(dual<parDDon,(rolling(reboots)

    • Omaha(update(protocol(en(SDK(van( Google's(Chrome(OS • Geen(package(manager(dus((gebruik(je( containers(voor) • coreos.com/using<coreos
  3. Deployment:+systemd • Systeem(en(service(manager • Zit(tegenwoordig(in(veel(Linux(distributes,(ook(in(CoreOS • Unit(files [Unit] Description=Hello World

    Service Requires=docker.service After=docker.service [Service] ExecStart=/usr/bin/docker run busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done" [Install] WantedBy=multi-user.target
  4. Service'Announcement:'ExecStartPost'&'ExecStopPost [Unit] Description=My Advanced Service After=etcd.service After=docker.service [Service] TimeoutStartSec=0 ExecStartPre=-/usr/bin/docker

    kill apache1 ExecStartPre=-/usr/bin/docker rm apache1 ExecStartPre=/usr/bin/docker pull coreos/apache ExecStart=/usr/bin/docker run --name apache1 -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND ExecStartPost=/usr/bin/etcdctl set /domains/example.com/10.10.10.123:8081 running ExecStop=/usr/bin/docker stop apache1 ExecStopPost=/usr/bin/etcdctl rm /domains/example.com/10.10.10.123:8081 [Install] WantedBy=multi-user.target Zie$'Advanced$Unit$Files'.
  5. Service'Announcement:'Sidekick'containers [Unit] Description=Announce nginx1.service # Binds this unit and nginx1

    together. # When nginx1 is stopped, this unit will be stopped too. BindsTo=nginx1.service [Service] ExecStart=/bin/sh -c "while true; do etcdctl set /services/website/nginx1 \ '{ \"host\": \"%H\", \"port\": 8080, \"version\": \"52c7248a14\" }' \ --ttl 60;sleep 45;done" ExecStop=/usr/bin/etcdctl delete /services/website/nginx1 [X-Fleet] # This unit will always be colocated with nginx1.service MachineOf=nginx1.service Zie$'Run$a$Simple$Sidekick'$en$service4discovery.md.
  6. Demo%op%Digital%Ocean • 3#CoreOS#hosts#met#global#units#(i.e.#op#elke#host)#registrator#en#vulcand • Een#NodeJS#demo#applica?e,#deze#print#de#Docker#containerCid#en#applica?eversie • Meerdere#versies#draaien#naast#elkaar#(v0.1.0#en#v0.2.0) • Van#elke#versie#een#aantal#instan?es#(containers) •

    Switchen#van#vulcand#frontend#van#v0.1.0#backend#naar#v0.2.0#backend#(blue/green#deployment) • /health#URL#voor#health#check • REST#API#voor#beinvloeden#health#status#(simuleren#van#een#falende#health#check) • N.B.#Voor#deze#demo#gebruik#ik#roundCrobin#DNS#en#geen#firstChop#redundancy#/#elas?c#IP#(zie# daarvoor#bijv.#CARP#/#VRRP,#AWS#Route#53,#e.d.) • Zie#github.com/MarcelHarkema/DockerGrunnCMeetupC20150303
  7. Re Re Re External LB Docker container met vulcand Docker

    container met Demo applicatie Legenda CoreOS-1 CoreOS-2 CoreOS-3 De Vu Vu De De Vu etcd etcd etcd Verzoeken vanuit vulcand op CoreOS-1 Verzoeken vanuit vulcand op CoreOS-2 Verzoeken vanuit vulcand op CoreOS-3 demo-application.qahwah.io Docker container met Registrator
  8. Wat$draait$er? $"fleetctl"list*units UNIT MACHINE ACTIVE SUB [email protected] e9436653.../10.133.191.90 active running

    [email protected] 1f264d10.../10.133.191.84 active running [email protected] 1f264d10.../10.133.191.84 active running [email protected] 9b655596.../10.133.191.87 active running registrator-vulcand.service 1f264d10.../10.133.191.84 active running registrator-vulcand.service 9b655596.../10.133.191.87 active running registrator-vulcand.service e9436653.../10.133.191.90 active running vulcand.service 1f264d10.../10.133.191.84 active running vulcand.service 9b655596.../10.133.191.87 active running vulcand.service e9436653.../10.133.191.90 active running
  9. systemd'unit'bij'demo'applica2e [Unit] Description=Demo application v0.2.0 After=docker.service Requires=docker.service [Service] ... Environment=IMAGE=marcelharkema/demo-application:0.2.0

    CONTAINER=demo-application-v0.2.0 ... ExecStart=/usr/bin/docker run --rm --name=${CONTAINER} \ -e SERVICE_ID=${CONTAINER}@%i \ -e SERVICE_NAME=${CONTAINER} \ -e SERVICE_FRONTEND_HOST_LOAD_BALANCER=${CONTAINER}.${DNS_DOMAIN} \ -e SERVICE_FRONTEND_HOST_CONTAINER=instance-%i.${CONTAINER}.${DNS_DOMAIN} \ -e SERVICE_CHECK_HTTP=/health \ -e SERVICE_CHECK_INTERVAL=3s \ -P ${IMAGE} ... [X-Fleet] Conflicts=${CONTAINER}*.service
  10. vulcand(keys(in(etcd:(een(frontend $"etcdctl"get"/vulcand/frontends/demo3applica6on3v0.2.0/frontend"|"./jq". { "Id": "demo-application-v0.2.0", "Route": "Host(\"demo-application-v0.2.0.qahwah.io\") && PathRegexp(\".*\")", "Type":

    "http", "BackendId": "demo-application-v0.2.0", "Settings": { "Limits": { "MaxMemBodyBytes": 0, "MaxBodyBytes": 0 }, "FailoverPredicate": "", "Hostname": "", "TrustForwardHeader": false } }
  11. vulcand(keys(in(etcd:(nog(een(frontend $"etcdctl"get"/vulcand/frontends/demo3applica6on3v0.2.0@1/frontend"|"./jq". { "Id": "demo-application-v0.2.0@1", "Route": "Host(\"instance-1.demo-application-v0.2.0.qahwah.io\") && PathRegexp(\".*\")", "Type":

    "http", "BackendId": "demo-application-v0.2.0@1", "Settings": { "Limits": { "MaxMemBodyBytes": 0, "MaxBodyBytes": 0 }, "FailoverPredicate": "", "Hostname": "", "TrustForwardHeader": false } }
  12. Simuleren)niet)healthy)applica0e $"etcdctl"get"/vulcand/backends/demo3applica6on3v0.2.0/servers/ demo3applica6on3v0.2.0@1"|"./jq". { "Id": "demo-application-v0.2.0@1", "URL": "http://10.133.191.84:49154" } $"curl"'H""Content'Type:"applica5on/json""'d"'{"health":false}'"\

    ""h@p:/ /10.133.191.84:49154/api/health De#container#wordt#uit#roula/e#genomen#na#een#falende#health#check: Mar 03 15:17:06 coreos-2.qahwah.io Health check demo-application-v0.2.0@1 (http://10.133.191.84:49154/health) result HTTP code 200 Mar 03 15:17:09 coreos-2.qahwah.io Health check demo-application-v0.2.0@1 (http://10.133.191.84:49154/health) result HTTP code 500
  13. Meerdere%versies%naast%elkaar%en%switchen demo%applica+on.qahwah.io1frontend1naar1servers1van1backend1 demo%applica+on%v0.2.01wijzen: $ docker exec vulcand vctl frontend upsert

    \ -id demo-application.qahwah.io \ -b demo-application-v0.2.0 \ -route 'Host(`demo-application.qahwah.io`) && PathRegexp(`.*`)' OK: frontend upserted