title: Managing DB migrations on Kubernetes cluster
body: <p>I have a Kubernetes based application consisting of multiple services (and pods) managed with helm chart.</p>
  
  <p>Postgres is used as a database for all services.</p>
  
  <p>When application is upgraded to a newer version, I am running a db migration script via <code>initContainers</code>.</p>
  
  <p>The problem occurs when migration scripts require an exclusive access to DB (all other connections should be terminated), otherwise the script is blocked.</p>
  
  <p>Ideal solution would be to stop all pods, run the migration and recreate them. But I am not sure how to achieve it properly with Kubernetes.</p>
  
  <p>Tnx</p>