Home > Software design >  How to update schema and data for a database deployed on kubernetes?
How to update schema and data for a database deployed on kubernetes?

Time:06-27

I'm trying to understand how to manage a Postgres database deployed on a Kubernetes cluster. So far, I can deploy a pod with the Postgres image. I'm also able to create persistent volume and persistent volume claims, but there is something that still I can't understand.

If I have a production database and at some point, I need to patch the database, what is the way to proceed? Is there a way to execute a SQL instruction to update schema and data?

CodePudding user response:

The easiest approach would be to connect to your database via port-forwarding, e.g.:

while true; do kubectl port-forward "$path" -n "$namespace" "$ports"; done

Better stop all downstream Pods that connect to this database. Then do what you need to do with a Postgres client of your choice.

More robustly, introduce a tool like Flyway or Liquibase for schema changes, which would get executed from inside the cluster and allow to version and track your DB changes.

  • Related