Journey to Deploying Rails on
Kubernetes
Rahul Mahale. BigBinary
Slide 2
Slide 2 text
$whoami
●
Works @ BigBinary
●
A FOSS Enthusiastic
●
Shipping Containers to Production
@Rahul_Mahale
Slide 3
Slide 3 text
Agenda
●
Walk you through how we deployed our
production application on Kubernetes.
Slide 4
Slide 4 text
Two Grounds
●
Provisioning production ready k8s cluster
●
Deploying Ruby on Rails application on k8s
cluster
Slide 5
Slide 5 text
K8s production cluster should be
●
Highly available.
●
Behind VPN(Secured Networking)
●
Auto-Scalable
Slide 6
Slide 6 text
How to ?
●
Provision HA cluster using Kops, Kubeadm
●
Private networking using Calico/weave/flannel
●
Use Cluster-autoscaler k8s addon
Slide 7
Slide 7 text
Rails deployment flow
●
Deploy a new code-base on each subsequent
deployment.
●
Build an image
●
Push it to docker registry(dockerhub,quay,self
hosted)
●
Pull the image and deploy change with zero
down time.
Image building
●
Automatic image building using.
➔
Dockerhub/dockercloud
➔
Quay.io
➔
ECS
➔
Self-hosted Jenkins
Slide 10
Slide 10 text
Kubernetes terminologies
●
Deployments
●
Services
●
Configmaps
●
Secrets
●
Jobs
●
Scheduled Jobs
Slide 11
Slide 11 text
Where to host database ?
●
On kubernetes ? At your own risk.
●
We host our DB on AWS RDS and on k8s using
PVC
●
Pre-created on launch of the new application.
Slide 12
Slide 12 text
K8s isolation
●
App running with app server like unicorn/puma
●
Web server to serve the app like nginx
●
Load balancer configured it with domain.
●
Background jobs like Sidekiq/Delayed Job.
●
Cron jobs.
●
Custom rake tasks
Slide 13
Slide 13 text
How things happen
●
Create namespace, secrets etc.
●
App deployment with app server unicorn
●
Deployment with nginx
●
Deployment for background job
●
Service for each deployment
●
Fetch database configuration from configmap
●
Fetch sidekiq from configmap.
●
Create jobs/cronjobs
Slide 14
Slide 14 text
Production things
●
Separate namespace for each app
●
Label nodes
●
ABAC/RBAC mode to distribute kubectl
configuration with devs.
●
Specify resources limit.
Slide 15
Slide 15 text
Zero downtime deployment
●
Healthcheck
●
Rediness probe
Slide 16
Slide 16 text
Autoscaling of app
●
Horizontal pod auto-scaler(HPA)
●
Memory based auto-scaler(own)
Slide 17
Slide 17 text
Jobs
Use it for custom tasks
Slide 18
Slide 18 text
Scheduled Jobs
●
Need to restart api server for enabling it with
--runtime-config=batch/v2alpha1
●
Restart policy, restartPolicy: OnFailure
●
Runs our Cron Jobs
●
We are coming up with our own tool for parsing
whenever cron to k8s cronjobs
Slide 19
Slide 19 text
Known issues
●
Issue #42164
➔
Restart docker or terminate node
●
Pods with PVCs doesnt scale
➔
you should check Statefulset
Slide 20
Slide 20 text
Monitoring
●
Cluster monitoring using Prometheus and
Grafana
●
Configure Prometheus alerts to notify on
slack/email etc.
Slide 21
Slide 21 text
Logging
●
ELK addon from Kubernetes
Slide 22
Slide 22 text
Automation
●
Create artifacts using something likke Ansible
or your own tool, create database, secrets etc.
➔
Creates deployment templates.
●
Helm is good tool from k8s community.
●
kubectl or k8s API
●
Label nodes script
Slide 23
Slide 23 text
Backup of Cluster
●
Etcd is heart of the k8s cluster.
●
Consider backing it up using something like
reshifter.
https://github.com/mhausenblas/reshifter