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

Operating Rails in Kubernetes

Operating Rails in Kubernetes

My talk at RailsConf 2018.

Kir Shatrov

April 17, 2018
Tweet

More Decks by Kir Shatrov

Other Decks in Programming

Transcript

  1. Operating Rails in Kubernetes
    Kir Shatrov

    View full-size slide

  2. 1. Intro to Kubernetes
    2. Rails in Kubernetes
    3. Shopify’s migration story

    View full-size slide

  3. Containers are awesome! *

    View full-size slide

  4. Containerizing Rails: Techniques, Pitfalls, & Best
    Practices
    by Daniel Azuma
    Tomorrow 3:30pm

    View full-size slide

  5. app01 app02 app03

    View full-size slide

  6. app01 app02 app03

    View full-size slide

  7. Smart container scheduling for better utilization

    View full-size slide

  8. Smart container scheduling for better utilization

    View full-size slide

  9. Smart container scheduling for better utilization

    View full-size slide

  10. Kubernetes basics: Pod

    View full-size slide

  11. Kubernetes basics: Deployment

    View full-size slide

  12. web jobs
    Kubernetes basics: Deployment

    View full-size slide

  13. web jobs
    Kubernetes basics: Deployment

    View full-size slide

  14. web jobs
    Kubernetes basics: Deployment

    View full-size slide

  15. web jobs
    Kubernetes basics: Deployment

    View full-size slide

  16. Managing Resources

    View full-size slide

  17. YAML
    apply when changed

    View full-size slide

  18. YAML
    store in repository

    View full-size slide

  19. Deploy process
    controlling servers

    View full-size slide

  20. Deploy process
    sequentially applying commands by SSH

    View full-size slide

  21. Capistrano
    sequentially applying commands by SSH

    View full-size slide

  22. kubectl apply --file web.yml

    View full-size slide

  23. kubectl apply --file jobs.yml

    View full-size slide

  24. Controlling servers vs describing configuration

    View full-size slide

  25. Controlling servers Describing configuration
    running commands remotely
    comparing output with expected
    not prone to failures
    push configuration
    poll for it to apply
    abstracts from physical machines
    self-healing

    View full-size slide

  26. Controlling servers Describing configuration
    running commands remotely
    comparing output with expected
    not prone to failures
    push configuration
    poll for it to apply
    abstracts from physical machines
    self-healing

    View full-size slide

  27. It's easy to run a container,

    but not Rails

    View full-size slide

  28. The Twelve-Factor app

    View full-size slide

  29. Disposability
    and termination

    View full-size slide

  30. Web requests

    View full-size slide

  31. Background Jobs

    View full-size slide

  32. Long-running jobs

    View full-size slide

  33. Abort and re-enqueue

    View full-size slide

  34. Concurrency
    scale out via the process model

    View full-size slide

  35. rake assets:precompile

    View full-size slide

  36. Assets
    Shipped in container

    View full-size slide

  37. Database Migrations

    View full-size slide

  38. Migrations as a part of deploy

    View full-size slide

  39. Migrations as a part of deploy

    View full-size slide

  40. Asynchronous Migrations

    View full-size slide

  41. 1. Change code and add a migration 1. Add a migration
    2. Change code

    View full-size slide

  42. 1. Change code and add a migration 1. Add a migration
    2. Change code

    View full-size slide

  43. Asynchronous Migrations

    View full-size slide

  44. Secret Management

    View full-size slide

  45. Secrets in the environment

    View full-size slide

  46. Secrets in a container

    View full-size slide

  47. Secrets in a container

    View full-size slide

  48. Rails 5.2 Credentials

    View full-size slide

  49. ENV[‘RAILS_MASTER_KEY’]

    View full-size slide

  50. The Twelve Factors
    Let workers terminate gracefully
    Migrations as a part of deploy can be fragile
    Rails 5.2 Credentials + Kubernetes Secrets

    View full-size slide

  51. Kubernetes at Shopify

    View full-size slide

  52. Resource specs in YAML

    View full-size slide

  53. kubectl apply --file web.yml

    View full-size slide

  54. Let robots help humans to migrate apps
    Developers don’t have to write YAML configs
    kubernetes-deploy brings visibility into rollout progress

    View full-size slide

  55. Kubernetes helps organizations to efficiently schedule workload
    and save resources
    It’s not magic, it only schedules and runs your containers
    Things you need to know about Rails

    View full-size slide

  56. Thanks!
    @kirs
    @kirshatrov

    View full-size slide