I'm looking for a robust and reliable strategy to apply my database migrations once per application of my Deployment yaml file to use in my CI/CD pipeline.
The initial (no pun intended) plan was to use initContainers to perform the migration. The difficulty I'm encountering has to do with the method of connecting to the CloudSQL database--since I'm using the gcr.io/cloudsql-docker/gce-proxy:1.11 sidecar container to let my application containers connect, I'm not sure how to provide the database access to the initContainers because they appear to only support single containers pods. Is it possible to run the proxy container as a sidecar on the initContainers?
If that is not possible, what is the preferred approach? Should the entrypoint of the application containers apply the migrations before launching the application itself? My concern is that in an initial launch of the deployments might create race conditions with multiple pods trying to apply migrations simultaneously?