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

Journey to deploying rails on Kubernetes

Journey to deploying rails on Kubernetes

Avatar for Rahul Mahale

Rahul Mahale

July 14, 2017
Tweet

More Decks by Rahul Mahale

Other Decks in Technology

Transcript

  1. $whoami • Works @ BigBinary • A FOSS Enthusiastic •

    Shipping Containers to Production @Rahul_Mahale
  2. K8s production cluster should be • Highly available. • Behind

    VPN(Secured Networking) • Auto-Scalable
  3. How to ? • Provision HA cluster using Kops, Kubeadm

    • Private networking using Calico/weave/flannel • Use Cluster-autoscaler k8s addon
  4. 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.
  5. Rails deployment flow • Update configuration rake task • rake

    assets:precompile • rake db:create or db:migrate • rake db:seed • Update jobs/cronjobs • restart the services.
  6. 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.
  7. 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
  8. 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
  9. Production things • Separate namespace for each app • Label

    nodes • ABAC/RBAC mode to distribute kubectl configuration with devs. • Specify resources limit.
  10. 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
  11. Known issues • Issue #42164 ➔ Restart docker or terminate

    node • Pods with PVCs doesnt scale ➔ you should check Statefulset
  12. 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
  13. Backup of Cluster • Etcd is heart of the k8s

    cluster. • Consider backing it up using something like reshifter. https://github.com/mhausenblas/reshifter