Scaling WordPress with Containers - WordPress London November 2017

Scaling WordPress with Containers - WordPress London November 2017

335072828e0fd0fdc46185ba365bee8e?s=128

craigwillis85

December 01, 2017
Tweet

Transcript

  1. Scaling WordPress with containers 30/11/17 WordPress 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. None
  10. Vertical Scaling Shared hosting? 1GB VPS? Dedicated Server

  11. Horizontal Scaling

  12. Horizontal Scaling 1GB VPS Lots

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

    Server Experience
  14. Steps to scale

  15. Split up the application/infrastructure

  16. Databases Files Sessions Web servers

  17. Forget about local storage

  18. Use a CDN

  19. Servers are cattle not pets

  20. Servers die

  21. We’ll come back to scaling later

  22. Ok, lets look at containers

  23. What is a container?

  24. What is a container? Lightweight, stand-alone, executable package (.exe, .jar)

    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 Should do ONE thing only (PHP, Apache)
  25. None
  26. VMs vs Container

  27. Demo Application

  28. WordPress REST API VueJS https://github.com/craigwillis85/scaling-wordpress

  29. Local Development

  30. docker-compose

  31. docker-compose.yml

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

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

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

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

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

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

    'wordpressdemo' MYSQL_ALLOW_EMPTY_PASSWORD: 'true' ON_CREATE_DB: 'wordpressdemo' ports: - "3306:3306" wordpressdemoapp: image: craigwillis85/wp-demo:v1 volumes: - "./api:/var/www/html" - "./api/configs/wp-config-dev.php:/var/www/html/wp-config.php" ports: - "80:80"
  38. docker-compose up -d

  39. $ docker ps CONTAINER ID IMAGE PORTS NAMES f41a217b93a mysql:5.6

    0.0.0.0:3306->3306/tcp wordpressdemo_database 8ad8f1ad3a1c craigwillis85/wp-demo:v1 0.0.0.0:80->80/tcp wordpressdemo_demoapp
  40. Do NOT use docker-compose in production!

  41. How do we run our containers in production?

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

    and scaling of containerized applications
  44. Some Kubernetes basics

  45. None
  46. What we’re going to be building Internet http://www.scalingwp.com/posts VueJS Frontend

    Load Balancer API CALL
  47. Pods

  48. 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.
  49. Pods Server/Node Container

  50. Services

  51. 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
  52. Think of it as an internal load balancer diverting traffic

    to our pods/containers
  53. Pods Service 172.100.100.1 172.100.100.2 172.100.100.3

  54. Deployments

  55. 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.
  56. ReplicaSets

  57. 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.
  58. ReplicaSets replicas: 5

  59. This is all great, but how do I run Kubernetes?

  60. Kubernetes Engine https://console.cloud.google.com/kubernetes

  61. Creating a cluster

  62. None
  63. None
  64. None
  65. $ kubectl

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

    against Kubernetes clusters
  67. $ kubectl get nodes NAME STATUS AGE VERSION Gke-scaling-wordpress-default-pool-3359c7d4-42wv Ready

    1h v1.7.8-gke.0 Gke-scaling-wordpress-default-pool-3359c7d4-6rdr Ready 1h v1.7.8-gke.0 Gke-scaling-wordpress-default-pool-3359c7d4-l6sv Ready 1h v1.7.8-gke.0 Wahey! We have a cluster
  68. Autoscaling

  69. locust.io

  70. Scaling Demo What could go wrong...

  71. We’re hiring! https://www.ayima.com/join-us

  72. Thank you!

  73. Questions?