Sample Rails application deployed with Kubernetes and Helm
Switch branches/tags
Nothing to show
Clone or download
Kawahara Taisuke
Kawahara Taisuke add blog link to README
Latest commit ed9132e Jun 6, 2018
Permalink
Failed to load latest commit information.
.dockerenv expand sidekiq timeout to 60s May 9, 2018
app convert cable code to TypeScript Apr 11, 2018
bin supports graceful restart May 8, 2018
config change production log_level to info from debug Apr 21, 2018
db ./bin/rake db:migrate Apr 11, 2018
k8s add annotations to rails deployments May 31, 2018
lib supports sidekiq livenessProbe May 7, 2018
log rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
public rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
spec/models ./bin/rake db:migrate Apr 11, 2018
test ./bin/rake db:migrate Apr 11, 2018
tmp rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
vendor rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
.babelrc ./bin/rails webpacker:install Apr 10, 2018
.dockerignore add Dockerfile and docker-compose-preview.yml Apr 15, 2018
.envrc change environments on docker-compse.yml Apr 15, 2018
.gcloudignore add .gcloudignore Apr 29, 2018
.gitignore ./bin/rails webpacker:install Apr 10, 2018
.postcssrc.yml ./bin/rails webpacker:install Apr 10, 2018
.ruby-version fix ruby vertion to 2.5.1 Apr 10, 2018
Dockerfile fix BUNDLE_APP_CONFIG issue May 30, 2018
Gemfile add lograge Apr 20, 2018
Gemfile.lock add lograge Apr 20, 2018
Procfile add Procfile Apr 10, 2018
README.md add blog link to README Jun 6, 2018
Rakefile rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
config.ru rails new demoapp --database=mysql --skip-bundle Apr 10, 2018
docker-compose-preview.yml simplify .dockerenv files Apr 20, 2018
docker-compose.yml change environments on docker-compse.yml Apr 15, 2018
package.json convert cable code to TypeScript Apr 11, 2018
tsconfig.json ./bin/rails webpacker:install:typescript Apr 10, 2018
yarn.lock convert cable code to TypeScript Apr 11, 2018

README.md

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.