Cloud Native 7 min read

Automate Safe Database Migrations on Kubernetes with Spinnaker

Learn how to build a repeatable, secure Spinnaker pipeline that automatically runs database migrations and deploys a Go‑based API service to Kubernetes, using Docker images, Run Job stages, and environment variables, without writing custom scripts.

Programmer DD
Programmer DD
Programmer DD
Automate Safe Database Migrations on Kubernetes with Spinnaker

Introduction

This tutorial shows how to use Spinnaker to create a reliable deployment pipeline for a Go‑based sample application that includes both an API server and a database migration command. The pipeline pushes a new Docker image to a registry and then runs two actions: a database migration and the API deployment.

Sample Application

The example app provides a golang-sample-service binary with three commands: Help – shows help for any command Migrate – executes database migrations Server – starts the API server on port 3000

Deploying the API Server

First, create a simple Spinnaker pipeline that triggers when a new Docker image is pushed to the Quay registry.

Configure the trigger:

Add a Deploy stage and select the new image. In the "Container" section, set the port for the API server.

After saving, run the pipeline to deploy the first instance of the service to the target Kubernetes cluster.

Verify the service health on the "Clusters" tab; a green instance indicates a successful deployment.

Adding Database Migration

Next, add a Run Job stage that will execute the migration before the Deploy stage. The job runs in a Kubernetes pod using the same Docker image but invokes the Migrate command instead of Server.

Configure the Run Job stage (no ports needed) and add environment variables so the migration framework can connect to the Postgres database inside the cluster.

Set the command to migrate up --dir={migrations-directory} and supply the required environment variables in the "Container" section.

Link the Run Job to the Deploy stage by adding a dependency: the Deploy stage depends on the successful completion of the "Run Database Migrations" job.

Now, executing the pipeline will first run the migration job and, upon success, proceed to deploy the API server.

Conclusion

Delivering software safely to production requires more than a simple helm install. Spinnaker provides a unified, script‑free way to orchestrate complex deployment workflows—including database migrations—using reusable stages, making the process repeatable, reliable, and easier to manage across teams.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud Nativeci/cdKubernetesDevOpsdatabase migrationSpinnaker
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.