/rails-k8s-demoapp

Sample Rails application deployed with Kubernetes and Helm

Primary LanguageRuby

Sample application for Docker/Kubernetes/Helm with Rails

Minimal sample application to demonstrate Rails application development with Docker, Kubernetes and Helm.

See blog for details.

Start preview mode with Docker Compose

Prerequisites

  • Docker, Docker Compose
$ git clone https://github.com/kwhrtsk/rails-k8s-demoapp.git
$ cd rails-k8s-demoapp

# Start mysql and redis container, and build rails app image and start.
$ docker-compose -f docker-compose-preview.yml up -d

# Open top page in your browser
$ open http://localhost:3000/

# Stop all containers and cleanup volumes
$ docker-compose -f docker-compose-preview.yml down

Start local server processes with MySQL and Redis on Docker Compose

Prerequisites

  • Docker, Docker Compose
  • Ruby 2.5.1
  • Node.js 6.0.0+
  • Yarn 0.25.2+
  • foreman
$ git clone https://github.com/kwhrtsk/rails-k8s-demoapp.git
$ cd rails-k8s-demoapp

# Start mysql and redis container
$ docker-compose up -d

# Install rubygems
$ bundle install
$ gem install foreman

# Install npm
$ yarn install

# Initialize database
$ ./bin/rails db:setup

# Start puma, sidekiq and webpack-dev-server
$ foreman start -f Procfile
# In another terminal, open top page in your browser.
$ open http://localhost:3000/

Kubernetes

Tested with:

Name Version
minikube 0.27.0 (k8s 1.10.0)
kubectl 1.10.2
helm 2.9.1
hyperkit v0.20171204-60-g0e5b6b
stern 1.6.0

Deploy to Kubernetes cluster with plain YAML manifest files

Example manifests to deploy to minikube instance.

  • step1
    • Use only these API Object: Deployment, Service, ConfigMap, Secret
  • step2
    • Add Job from step1's constitution to execute rails db:setup.
    • Supports multiple puma containers.
  • step3
    • Add PersistentVolumeClaim from step2's constitution to persistent data of mysql and redis.
  • step4
    • Add Ingress from step3's constitution to expose application with custom TLS certificate and fixed URL.

Deploy to Kubernetes cluster with Helm Chart

Helm Chart example and operation scripts for setup, deploy, and rolling update rails containers. This chart based on manifests-step4.