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

Scaling WordPress with containers - WPHooked June 2017

Scaling WordPress with containers - WPHooked June 2017

335072828e0fd0fdc46185ba365bee8e?s=128

craigwillis85

June 14, 2017
Tweet

Transcript

  1. Scaling WordPress with containers 13/06/17 WP Hooked London

  2. Who am I? Craig Willis Web Developer @ Ayima Co-organiser

    PHP London @craigwillis85
  3. What is scalability?

  4. https://en.wikipedia.org/wiki/Scalability Scalability is the capability of a system, network, or

    process to handle a growing amount of work, or its potential to be enlarged to accommodate that growth
  5. So what does that mean?

  6. None
  7. Traditional scaling techniques

  8. Vertical Scaling

  9. Horizontal Scaling

  10. Speed != Scale https://www.slideshare.net/ircmaxell/high-performance-php-phpnw Speed == User Experience Scale ==

    Server Experience
  11. Steps to scale

  12. Split up the application/infrastructure

  13. Databases Files Sessions Web servers

  14. Forget about local storage

  15. Servers are cattle not pets

  16. We’ll come back to scaling later

  17. Ok, lets look at containers

  18. What is a container?

  19. What is a container? Lightweight, stand-alone, executable package Includes everything

    it needs to run Runtime, system tools, libraries, settings Built on top of facilities of linux kernel Does not include / require a separate operating system
  20. None
  21. Demo Application

  22. WordPress REST API VueJS

  23. docker-compose

  24. docker-compose.yml

  25. version: '2' services: database: image: mysql:5.6 environment: MYSQL_USER: 'root' MYSQL_DATABASE:

    'wphookeddemo' MYSQL_ALLOW_EMPTY_PASSWORD: 'true' ON_CREATE_DB: 'wphookeddemo' ports: - "3306:3306" demoapp: image: craigwillis85/wp-demo:latest volumes: - "./public:/var/www/html" - "./public/wp-config-dev.php:/var/www/html/wp-config.php" ports: - "80:80"
  26. version: '2' services: database: image: mysql:5.6 environment: MYSQL_USER: 'root' MYSQL_DATABASE:

    'wphookeddemo' MYSQL_ALLOW_EMPTY_PASSWORD: 'true' ON_CREATE_DB: 'wphookeddemo' ports: - "3306:3306" demoapp: image: craigwillis85/wp-demo:latest volumes: - "./public:/var/www/html" - "./public/wp-config-dev.php:/var/www/html/wp-config.php" ports: - "80:80"
  27. version: '2' services: database: image: mysql:5.6 environment: MYSQL_USER: 'root' MYSQL_DATABASE:

    'wphookeddemo' MYSQL_ALLOW_EMPTY_PASSWORD: 'true' ON_CREATE_DB: 'wphookeddemo' ports: - "3306:3306" demoapp: image: craigwillis85/wp-demo:latest volumes: - "./public:/var/www/html" - "./public/wp-config-dev.php:/var/www/html/wp-config.php" ports: - "80:80"
  28. version: '2' services: database: image: mysql:5.6 environment: MYSQL_USER: 'root' MYSQL_DATABASE:

    'wphookeddemo' MYSQL_ALLOW_EMPTY_PASSWORD: 'true' ON_CREATE_DB: 'wphookeddemo' ports: - "3306:3306" demoapp: image: craigwillis85/wp-demo:latest volumes: - "./public:/var/www/html" - "./public/wp-config-dev.php:/var/www/html/wp-config.php" ports: - "80:80"
  29. docker-compose up -d

  30. $ docker ps CONTAINER ID IMAGE PORTS NAMES f41a217b93aa mysql:5.6

    0.0.0.0:3306->3306/tcp wphookedwordpress_database 8ad8f1ad3a1c craigwillis85/wp-demo:latest 0.0.0.0:80->80/tcp wphookedwordpress_demoapp
  31. Do NOT use docker-compose in production!

  32. How do we run our containers in production?

  33. None
  34. https://kubernetes.io Kubernetes is an open-source system for automating deployment, management

    and scaling of containerized applications
  35. What we’re going to be building Internet http://d2mc1n7mzp6nc0.cloudfront.net http://xxxxxx.cloudfront.net CloudFront

    S3 ELB EC2 RDS API CALL api.myawesomewebsite.com
  36. A Pod is a collection of containers sharing a network

    and mount namespace and is the basic unit of deployment in Kubernetes. All containers in a pod are scheduled on the same node.
  37. Pods Server

  38. Services

  39. A Service is an abstraction for pods, providing a stable,

    virtual IP (VIP) address allowing clients to reliably connect to the containers by forwarding traffic to one or more pods
  40. Think of it as an internal load balancer diverting traffic

    to our pods/containers
  41. Pods Service

  42. apiVersion: v1 kind: Service metadata: name: wordpress spec: ports: -

    name: http port: 80 protocol: TCP targetPort: http selector: name: wordpress type: LoadBalancer
  43. Deployments

  44. A deployment is a supervisor for pods and replica sets,

    giving you fine-grained control over how and when a new pod version is rolled out as well as rolled back to a previous state.
  45. apiVersion: extensions/v1beta1 kind: Deployment metadata: name: wordpress labels: name: wordpress

    spec: replicas: 5 template: metadata: labels: name: wordpress ………………..
  46. spec: containers: - name: wordpress image: craigwillis85/wp-demo:latest imagePullPolicy: Always env:

    - name: GET_HOSTS_FROM value: dns ports: - containerPort: 80 name: http protocol: TCP imagePullSecrets: - name: docker restartPolicy: Always
  47. ReplicaSets

  48. A ReplicaSet is a supervisor for long-running pods. An RC

    will launch a specified number of pods called replicas and makes sure that they keep running, for example when a node fails or something inside of a pod, that is, in one of its containers goes wrong.
  49. ReplicaSets replicas: 5

  50. This is all great, but what about running this in

    production?
  51. kops https://github.com/kubernetes/kops

  52. https://github.com/kubernetes/kops kops helps you create, destroy, upgrade and maintain production-grade,

    highly available Kubernetes clusters from the command line
  53. Creating a cluster

  54. export NAME=cluster.wphooked-demo.site export ZONES=${ZONES:-"eu-west-1a"} export NODE_SIZE=${NODE_SIZE:-m4.large} export MASTER_SIZE=${MASTER_SIZE:-m4.large} export AWS_ACCESS_KEY_ID=BLAHBLAH

    export AWS_SECRET_ACCESS_KEY=BLAHBLAH
  55. kops create cluster $NAME \ --node-count 2 \ --zones $ZONES

    \ --node-size $NODE_SIZE \ --master-size $MASTER_SIZE \ --master-zones $ZONES \ --networking weave \ --topology private \ --bastion="true" \ --yes
  56. Wahey! We have a cluster

  57. $ kubectl

  58. https://kubernetes.io/docs/user-guide/kubectl kubectl is a command line interface for running commands

    against Kubernetes clusters
  59. $ kubectl get nodes NAME STATUS AGE VERSION ip-172-20-50-31…. Ready,master

    1h v1.6.2 ip-172-20-55-31…. Ready,node 1h v1.6.2 ip-172-20-56-48…. Ready,node 1h v1.6.2
  60. cluster-autoscaler

  61. heapster

  62. Horizontal Pod Autoscaler (HPA)

  63. locust.io

  64. Scaling Demo What could go wrong...

  65. Thank you!

  66. Questions?