Journey to deploying rails on Kubernetes

Journey to deploying rails on Kubernetes

4668924ca3c52d96b56315cecb6a4f69?s=128

Rahul Mahale

July 14, 2017
Tweet

Transcript

  1. 2.

    $whoami • Works @ BigBinary • A FOSS Enthusiastic •

    Shipping Containers to Production @Rahul_Mahale
  2. 5.

    K8s production cluster should be • Highly available. • Behind

    VPN(Secured Networking) • Auto-Scalable
  3. 6.

    How to ? • Provision HA cluster using Kops, Kubeadm

    • Private networking using Calico/weave/flannel • Use Cluster-autoscaler k8s addon
  4. 7.

    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. 8.

    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. 11.

    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. 12.

    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. 13.

    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. 14.

    Production things • Separate namespace for each app • Label

    nodes • ABAC/RBAC mode to distribute kubectl configuration with devs. • Specify resources limit.
  10. 18.

    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. 19.

    Known issues • Issue #42164 ➔ Restart docker or terminate

    node • Pods with PVCs doesnt scale ➔ you should check Statefulset
  12. 20.
  13. 22.

    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
  14. 23.

    Backup of Cluster • Etcd is heart of the k8s

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