CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster

46
{ CoreOS in anger Shaun Domingo - @sdomsta Head of Tech and Operations @ Ninefold

Transcript of CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster

  1. 1. {CoreOS in anger Shaun Domingo - @sdomsta Head of Tech and Operations @ Ninefold
  2. 2. The inevitable recap
  3. 3. Why CoreOS? Built-in clustering Few binaries No packaging system Dependent on containers for managing software and apps Light weight, fat-free Automatic updates
  4. 4. A single, distributed init system Encourages small, ephemeral units / services Schedules units into the cluster based on declared conflicts in systemd unit files Fault tolerant Can be managed locally or remotely by fleetctl CoreOS building blocks systemd fleet etcd
  5. 5. Orchestration DIY Kubernetes (Google) Mesos + Marathon (Apache) CoreOS arsenal etcd fleet flannel docker rocket
  6. 6. +---------------+ +----------------+ +----------------+ | | | | | | | core-01 | | core-02 | | core-03 | | | etcd | | etcd | | +---------------+ +----------------+ +----------------+ Exercise 1: Boot up a 3 machine coreos cluster
  7. 7. Download & install Vagrant: http://www.vagrantup.com/downloads.html Download & install Virtualbox: https://www.virtualbox.org/wiki/Downloads 1a: install VirtualBox
  8. 8. mkdir ~/coreos; cd ~/coreos git clone https://github.com/coreos/coreos- vagrant.git 1b: Clone the coreos- vagrant repo
  9. 9. cd coreos-vagrant cp config.rb.sample config.rb vim config.rb change $num_instances: $num_instances=3 change $update_channel: $update_channel=beta Change $forwarded_ports: $forwarded_ports = {8000 => 8888} 1c: modify your config.rb Well use this later Youll get 3 CoreOS VMs alpha if you like bleeding edge, stable if you want to stay sane.
  10. 10. Visit https://discovery.etcd.io/new?size=3 (youll need a new one every time you destroy a cluster) Copy the entire URL provided in the body of the response 1d: get yourself a discovery token
  11. 11. 4c4,6 < etcd: --- > update: > reboot-strategy: etcd-lock > # etcd: 8,9c10,11 < addr: $public_ipv4:4001 < peer-addr: $public_ipv4:7001 --- > #addr: $public_ipv4:4001 > #peer-addr: $public_ipv4:7001 12c14 < #discovery: https://discovery.etcd.io/ --- > discovery: https://discovery.etcd.io/YOUR_DISCOVERY_TOKEN_HERE 25,26c27,28 < - name: etcd.service < command: start --- > #- name: etcd.service > # command: start 29,30c31,32 < #- name: etcd2.service < # command: start --- > - name: etcd2.service > command: start 1e: modify your user-data and turn on etcd2 Reboot after first taking a lock in etcd Disable etcd (version 1) Enable etcd2.service, disable etcd.service Add your copied discovery token here
  12. 12. The $private_ipv4 and $public_ipv4 substitutio n variables are fully supported in cloud-config on Vagrant. They will map to the first statically defined private and public networks defined in the Vagrantfile. A note on $private_ipv4 and $public_ipv4 substitution variables
  13. 13. Examine the vagrant file
  14. 14. vagrant up vagrant status 1f: magic
  15. 15. ACHIEVEMENT UNLOCKED!
  16. 16. Exercise 2: Get talking to your cluster
  17. 17. https://github.com/coreos/fleet/releases Unzip, add the binary to your path (.bashrc / .bash_profile / .zshrc) PATH=$PATH:/path/to/fleetctl Restart your terminal 2a: Download fleetctl
  18. 18. cd /path/to/coreos-vagrant eval $(ssh-agent) # Add the correct vagrant .ssh identity vagrant ssh-config | sed -n "s/IdentityFile//gp" | uniq | xargs ssh-add 2b: start your engines Ensure ssh-agent is running NOTE: Youll need to rerun these steps each time you blow away your vagrant CoreOS cluster.
  19. 19. export FLEETCTL_TUNNEL="127.0.0.1:$(vagrant ssh- config | grep -i 'port' | awk '{print $2; exit}')" # remove your fleet known hosts rm ~/.fleetctl/known_hosts 2c: Prepare for takeoff NOTE: Youll need to rerun these steps each time you blow away your vagrant CoreOS cluster.
  20. 20. fleetctl list-machines 2d: go go go
  21. 21. Need to tweak? Do it all in the comfort of 127.0.0.1.
  22. 22. Exercise 3: Web Scale
  23. 23. Containers, microservices => stateless Containers => spin them up quick Load balancing => how does it work? Considerations at scale
  24. 24. When we start a unit, auto-add it to the web cluster When we destroy a unit, auto-remove it from the web cluster When a container is flakey, dont use it Spin up lots of my units without a hassle Desired
  25. 25. +----------------------------+ | | | Web server / RP | | | +-------------+--------------+ | +-------------+--------------+ | | | App server | | | +-------------+--------------+ | +-------------+--------------+ | | | Database | | | +----------------------------+ Standard 3-tier architecture
  26. 26. +----------------------------+ | | | Web server / RP | | | +-------------+--------------+ | +-------------+--------------+ | | | App server | | | +-------------+--------------+ | +-------------+--------------+ | | | Database | | | +----------------------------+ just wont work here. Needs to scale, be fault tolerant, have speed and be nearby.
  27. 27. +----------------------------+ | | | Web server / RP | | | +-------------+--------------+ | +-------------+--------------+ | | | App server | | | +-------------+--------------+ | +-------------+--------------+ | | | Database | | | +----------------------------+ just wont work here. Needs to be stateless, needs to focus on dynamic workloads.
  28. 28. +----------------------------+ | | | Web server / RP | | | +-------------+--------------+ | +-------------+--------------+ | | | App server | | | +-------------+--------------+ | +-------------+--------------+ | | | Database | | | +----------------------------+ just wont work here. Needs to handle caching, should really be a CDN, should be great at delivering static content.
  29. 29. CDN is a must S3 for asset sync Cache as much as you can varnish, CloudFront Load balancing Web server as a RP App server / runtime Database as a service Key/value store e.g. redis, cache as much as you can To achieve true web scale
  30. 30. Tonights example: Wordpress at (localhost) scale A traditional app, not written with containers and true scale in mind. Yet it is still incredibly popular as a blogging and web platform worldwide. Localhost scale
  31. 31. +---------80----------+ +------------+ | | | CDN |