Skip to content

A guide to deploying a Rails application with Kubernetes.

Notifications You must be signed in to change notification settings

anolson/k8s-rails

Repository files navigation

Overview

This is an example application and guide for deploying a Rails application with Kubernetes. The instructions below use minikube, but they should apply to any Kubernetes cluster.

Getting Started

Install minikube

$ brew install minikube
$ minikube start

And (optionally) start the dashboard with:

$ minikube dashboard

Deploy Postgres

Create the volume, service, and deployment with:

$ kubectl apply -f kube/postgres

View logs with:

$ kubectl logs -f deployments/postgres

Deploy Rails

Build the docker image

First, we need to build our app image. One of nice things about minikube is that it allows you to build docker images without needing to push to an external registry.

https://minikube.sigs.k8s.io/docs/handbook/pushing/#1-pushing-directly-to-the-in-cluster-docker-daemon-docker-env

$ eval $(minikube docker-env)
$ docker build -t quotes:latest .

DB Setup:

$ kubectl apply -f kube/setup.yml
$ kubectl logs -f jobs/setup

Create the service and deployment with:

$ kubectl apply -f kube/app

Open the service with:

$ minikube service quotes

Stop services

Stop minikube

$ minikube stop

Delete deployments, jobs, and services with:

kubectl delete deployments --all
kubectl delete jobs --all
kubectl delete services --all

Other resources

Guides

Documentation

Courses

Tools

Misc