Setup a Rails app with Kubernates and Orchestrate a Redis, Postgres pods deployment
Handle multiples pod services as database, cache and api as separate instances
Posted on June 06, 2025
Kubernetes is a widely adopted and more complex solution designed to support versatile, scalable services across diverse environments with multiple services (API, Backend, Webhook), or a more robust solution for managing all your environments, with zero downtime and the capability of test on production your newest changes (ie: canary deployment) is a very attractive option so how we integrate this tool on our Rails app.
Set up your PostgreSQL database volume
The first step is to definecat your volume, where your database is saved. if you have any experience with Kubernetes, you must know that a Volume and PersistentVolume are necessary. A persistent volume is a instance on K8 where you saved all your data.
Persistent Volume (local purpose). Here we are defining a local storage of 4Gb for write all database records.
Now we have the PostgreSQL credentials for out local environment
Redis and PostgreSQL instances
Now we have a storage for our database, so for this architecture we have a Redis instance and a Postgres database engine, but in case you have other services or DB engines, you can customize your solution.
Deployments are a way in K8 of indicating that we are creating a new instance of a specific service; there are many many options customized for deployments.
Redis
In the containers section set up the version image name (docker image)
3. The local environment variables loaded from our config map.
envFrom:
- configMapRef:
name: app-settings
Postgres and Redis services
Now that we have our app running Redis and PostgreSQL, we must open access to both services using a Kubernetes service. One indicator decisive to our services is indicated by our selector tag, in both cases is web.
Redis Service
apiVersion: v1
kind: Service
metadata:
name: redis
labels:
app: web
spec:
ports:
- port: 6379
selector:
app: web
tier: redis
Postgres Service
apiVersion: v1
kind: Service
metadata:
name: postgres-rails
labels:
app: web
spec:
#type: ClusterIP
ports:
- port: 5432
targetPort: 5432
protocol: TCP
selector:
app: web
tier: postgres-rails
App deployment
We have our PostgreSQL database instance, Redis instance for cache, the local volumes. Now we are ready to deploy our Rails app, using the config map for our environment variables. For this step, we must have a Docker image of our app on our local or submitted to Docker repository.