3. Who is this guy?
• Cameron Dutro
• I work at GitHub
• He/him/his
• Go Seahawks!
4. Rails is awesome
• Easy for beginners!
• Simple database tools!
• Super-fast development experience!
• A right place for every
fi
le!
• Generators! Gems! Community!
• Take that, Java!
“OOPS!”
6. Rails has no official tool orguide to aide in
deploying an app into production.
THE UNFORTUNATE TRUTH IS,
7. RR 403: Rails Needs Active Deployment
with Stefan Wintermeyer
March 12th, 2019
“ ”
In my experience, deployment is one of
the major problems of normal Rails
users… it is a big pain to set up a
deployment system for a Rails application,
and I don’t see anything out there that
makes it easier.
- Stefan Wintermeyer
8. RR 403: Rails Needs Active Deployment
with Stefan Wintermeyer
March 12th, 2019
“ ”
I believe that we lose quite a lot of
companies and new developers on this
step. Because everything else [is] so much
easier with Rails… but that last step - and
it’s a super important step - is still super
complicated.
- Stefan Wintermeyer
9. Our options
• Heroku? Expensive
• EC2 instance + capistrano? Dif
fi
cult
• EC2 instance + Chef/Puppet/Ansible? So much to learn
• Render, Fly, Cloud 66 Easy but vendor lock-in
10.
11. Today’s journey
Cameron circa 2000
• What do we mean by “deployment”?
• How deployment has changed in the last
~20 years
• The state-of-the-art in Rails land
• ActiveDeployment (a.k.a. Kuby)
12. What is deployment?
• You’ve built a great website and you want to put it online
• Need a computer to run it on
• (Ideally not your laptop)
• Need to install software that listens for requests, invokes
your code, and sends back the response
• Might need a domain name (mycoolsite.com)
• Might need persistent storage like a database
13. CCM Glass
• In 2002 I built my
fi
rst website
• Pure hand-coded HTML
• Deployed to free hosting provider
• Free hosting, powered by ads
• Files deployed via FTP
14. PHP (2004 - 2010)
• More dynamic
• Able to store and retrieve data from MySQL
• Still deploying via FTP
15. Fluther (2010)
• First job out of college
• Django app (Python)
• MySQL database
• Solr full-text search
• Deployed using Capistrano
“Dr. Jelly”
16. Twitter (2011)
• Thousands of app servers
• Deployments too slow using Capistrano
• Wrote our own deployment tool
• Servers pull code from each other via BitTorrent
• First server seeds new version
17. Twitter
• In 2013, Twitter switched to Apache Mesos
• “Program against your datacenter like it’s a single pool of resources”
• Many distinct services (geolocation, photos, twitter.com, etc)
• Services isolated from each other on the same host
• Resource allocation, ports, etc con
fi
gured declaratively
18. Lumos Labs
• 2014: VPSes in Softlayer
• Bespoke Capistrano setup + Chef
• Deployed via in-house web app called Catapult
• 2015: EC2 instances in AWS, still Capistrano
• 2016: Docker + ECS (Elastic Container Service)
• Deployed using in-house tool called Broadside
• 2017: Kubernetes
19. GitHub (2022)
• Dotcom
• Kubernetes, deployed via chat-ops
• Other services
• Self-service Kubernetes-based framework called Moda
• Kubernetes is the platform
• Tooling abstracts away the details
23. What I want from ActiveDeployment
• Launches my app. Runs my app on a remote server
• Ease of use. Con
fi
g should be easy to grok
• BYOS. Bring our own servers
• Endemicity. Rails-native
24. These would be nice too
• SSL/TLS certi
fi
cates installed/rotated automatically
• Managed database instance
• Sidekiq workers
• Static asset server
• No vendor lock-in
25. as turnkey as Heroku, as unrestricted as
Capistrano
BASICALLY I WANT IT TO BE
28. Capistrano
• Server automation tool written in Ruby
• Servers managed via remote SSH connections
• Uses Rake tasks under the hood
29. Why Capistrano?
• Simple. It’s just rake tasks + SSH
• Flexible. No limits on what you can do
• Established. We’ve got years of prior art to guide us
• Independent. No vendor lock-in
• Ruby. Written in the language we all love
30. Why not Capistrano?
• Bespoke. You have to do a lot of things yourself
• Imperative. Is your server really in the state you think it’s in?
• Not portable. Does everything still work if you upgrade the OS?
• Server-focused. Thinks of servers as individual machines
33. Why Kubernetes?
• Extensible. Provides a true platform
• Declarative. Tell Kubernetes what, not how
• Portable. Deploy to any cloud provider with no con
fi
g changes
• Cluster-focused. Servers are treated collectively as a single resource
• Resilient. Restarts failed processes automatically
• Scalable. Can scale on-demand
35. Introducing Kuby
• Kuby is ActiveDeployment for Rails apps
• Packages and deploys your app into a Kubernetes cluster
• Minimal, easy-to-read con
fi
guration
• Supports major cloud providers
• DigitalOcean, Linode, EKS (Amazon), Azure
36. Introducing Kuby
• Rails-native
• Deploys the secrets in credentials.yml
• Automatically provisions a database instance
• Creates a static asset server
• Acquires SSL/TLS certi
fi
cates for your domain
37. Starter config
Kuby.define('Railsconf') do
environment(:production) do
docker do
credentials do
username app_creds[:DOCKER_USERNAME]
password app_creds[:DOCKER_PASSWORD]
email app_creds[:DOCKER_EMAIL]
end
image_url "docker.pkg.github.com/camertron/railsconf/railsconf"
end
kubernetes do
add_plugin :rails_app
provider :linode do
cluster_id app_creds[:LINODE_CLUSTER_ID]
access_token app_creds[:LINODE_ACCESS_TOKEN]
end
end
end
end
38. Your first deploy
$> bundle exec kuby -e production build
$> bundle exec kuby -e production push
$> bundle exec kuby -e production deploy
$> bundle exec kuby -e production setup
43. Add Sidekiq
if Rails.env.production
?
Sidekiq.configure_server do |config
|
config.redis = Kuby.environment.kubernetes.plugin(:sidekiq).connection_param
s
end
Sidekiq.configure_client do |config
|
config.redis = Kuby.environment.kubernetes.plugin(:sidekiq).connection_param
s
end
end
In con
fi
g/initializers/sidekiq.rb:
44. Deploy Sidekiq
$> bundle exec kuby -e production build
$> bundle exec kuby -e production push
$> bundle exec kuby -e production deploy
$> bundle exec kuby -e production setup
(because we added a plugin)
45. The Platform
• Capistrano:
• Machine running FTP server or SSH daemon
• Kubernetes:
• Container scheduler, scaling, fault tolerance
• Networking, load-balancing, ingress/egress
• Persistent storage
• Role-based access control
46. Other things you can do
• kuby logs: Get logs from a web pod
• kuby remote shell: Like SSH - start an interactive shell in a web pod
• kuby remote console: Like rails console
• kuby remote dbconsole: Like rails dbconsole
• kuby kubectl: Run arbitrary kubectl commands
• … and much more