You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HYPERFLEET-937 - feat: add initSidecars support for Kubernetes native sidecar containers
Adds initSidecars list for injecting init containers with restartPolicy: Always
(Kubernetes 1.28+). These start before db-migrate, solving the deadlock where
database proxies in regular sidecars aren't available during migrations.
Copy file name to clipboardExpand all lines: docs/database.md
+69-21Lines changed: 69 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -184,11 +184,55 @@ The readiness probe (`/readyz`) pings the database with a separate timeout contr
184
184
185
185
## Sidecar Containers
186
186
187
-
The Helm chart supports generic sidecar injection via the `sidecars` list in `values.yaml`. Each entry is a full Kubernetes container spec injected into the deployment pod. This can be used for any purpose — database proxies, log shippers, monitoring agents, etc.
187
+
The Helm chart supports two sidecar injection mechanisms:
188
188
189
-
A common use case is database proxy sidecars (PgBouncer, Cloud SQL Auth Proxy). The example below shows a PgBouncer configuration.
189
+
| List | Where it renders | Starts when | Use case |
|`initSidecars`|`initContainers` (with `restartPolicy: Always`) | Before all other init containers | Database proxies that must be available during `db-migrate`|
192
+
|`sidecars`|`containers`| After all init containers complete | Log shippers, monitoring agents, connection poolers that don't need to run during init |
190
193
191
-
### Example: PgBouncer Sidecar
194
+
Each entry in either list is a full Kubernetes container spec injected as-is into the deployment pod.
195
+
196
+
### Native Sidecars (`initSidecars`)
197
+
198
+
Kubernetes 1.28+ supports [native sidecar containers](https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/) — init containers declared with `restartPolicy: Always`. They start before other init containers and keep running throughout the pod lifecycle.
199
+
200
+
Use `initSidecars` for database proxies (Cloud SQL Auth Proxy, AlloyDB Auth Proxy) that must be reachable when the `db-migrate` init container runs. Without this, the migration deadlocks: the init container waits for the proxy, but regular sidecars only start after all init containers finish.
With this setup, both the `db-migrate` init container and the runtime API container connect through the proxy — no `extraEnv` override needed since the proxy listens on `localhost:5432`.
232
+
233
+
### Regular Sidecars (`sidecars`)
234
+
235
+
Use the `sidecars` list for containers that don't need to be available during init. The example below shows a PgBouncer connection pooler:
192
236
193
237
```yaml
194
238
# values.yaml
@@ -233,7 +277,7 @@ sidecars:
233
277
memory: 64Mi
234
278
```
235
279
236
-
When using a proxy sidecar, the API container must connect to the proxy instead of PostgreSQL directly. The `database.external.secretName` secret must contain the **direct** database endpoint (host/port) so the `db-migrate` init container can run migrations before sidecars start. To route runtime traffic through the proxy, use `extraEnv` overrides in the main container:
280
+
When using a regular sidecarproxy, the `db-migrate` init container connects directly to the database (regular sidecars aren't running yet). Route runtime traffic through the proxy with `extraEnv`:
237
281
238
282
```yaml
239
283
extraEnv:
@@ -245,29 +289,33 @@ extraEnv:
245
289
246
290
Use `extraVolumes` and `extraVolumeMounts` for any volumes the sidecar requires (e.g., temp dirs, config dirs).
- Init containers (migrations) should connect directly to the database — they run before sidecars start, and DDL operations may not be compatible with connection pooling.
266
-
267
315
### Common Proxy Choices
268
316
269
-
- **PgBouncer**: Lightweight connection pooler. Use `transaction` pool mode for stateless APIs. See commented example in `values.yaml`.
270
-
- **Cloud SQL Auth Proxy**: Required for GCP Cloud SQL access without complex network/IP setup. See commented example in `values.yaml`.
317
+
- **Cloud SQL Auth Proxy**: Required for GCP Cloud SQL. Use `initSidecars` so migrations can reach the database through the proxy.
318
+
- **PgBouncer**: Lightweight connection pooler. Use `transaction` pool mode for stateless APIs. Can go in either `initSidecars` or `sidecars` depending on whether migrations need it.
0 commit comments