Files
conversation-history/SquareMCP/engineering/2026-06-17-zero-downtime-deploys.md
T

129 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Future: Zero-downtime hermes-mcp deploys
**Written:** 2026-06-17
**Target:** weekend of 2026-06-21
**Effort:** ~1–2 hours
---
## Current situation
hermes-mcp uses `hostNetwork: true` in its K8s deployment so the pod can reach
MySQL on `127.0.0.1:3306` (Docker container on the host). Because of this, the
deployment strategy is forced to `Recreate` — two pods can't bind the same host
port simultaneously. Every deploy has a 5–15 second outage: old pod killed, gap,
new pod starts.
---
## Goal
Switch to `RollingUpdate` with `maxUnavailable: 0, maxSurge: 1` so deploys are
seamless. A new pod starts and passes its readiness probe before the old one is
terminated.
---
## What needs to change
### 1. Expose MySQL to the pod network
The Docker MySQL container currently only listens on `127.0.0.1:3306`. Add a
`0.0.0.0:3306` binding (or at minimum bind to the Docker bridge IP, e.g.
`172.17.0.1:3306`) so the K8s pod network can reach it.
In `/home/garfield/docker-compose.fetcherpay.yml` (or whichever compose file
owns MySQL), change the port binding from:
```yaml
ports:
- "127.0.0.1:3306:3306"
```
to:
```yaml
ports:
- "3306:3306"
```
Or bind only to the docker0 bridge IP to avoid full public exposure:
```yaml
ports:
- "172.17.0.1:3306:3306"
```
### 2. Add a K8s Service for MySQL (optional but cleaner)
Create an `ExternalName` or `Endpoints` service in the `fetcherpay` namespace
pointing to the host's docker bridge IP. This lets hermes reference MySQL by a
stable DNS name (`mysql.fetcherpay.svc`) rather than a hardcoded IP, and makes
the binding easier to change later.
```yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: fetcherpay
spec:
type: ClusterIP
ports:
- port: 3306
---
apiVersion: v1
kind: Endpoints
metadata:
name: mysql
namespace: fetcherpay
subsets:
- addresses:
- ip: 172.17.0.1 # docker0 bridge IP — verify with: ip addr show docker0
ports:
- port: 3306
```
### 3. Update hermes-mcp env var
Change `MYSQL_HOST` (or equivalent) from `127.0.0.1` to `mysql.fetcherpay.svc`
(or `172.17.0.1` if skipping the K8s service).
### 4. Remove hostNetwork, switch strategy
In `hermes-k8s.yaml`:
```yaml
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
template:
spec:
# hostNetwork: true ← remove this line
```
---
## Verification
1. `kubectl rollout restart deployment/hermes-mcp -n fetcherpay` — watch for two
pods briefly coexisting, then old one terminating cleanly
2. Hit `GET /api/health` continuously during the rollout — no 502s or dropped
requests
3. Confirm MySQL connectivity from the new pod: check logs for connection errors
---
## Risk
- If `172.17.0.1` is not the right docker0 IP on art0, MySQL will be unreachable.
Verify first: `ip addr show docker0` on art0.
- MySQL port will be reachable from all K8s pods, not just hermes. Acceptable
for now given the internal network; add a NetworkPolicy later if needed.
- Do this off-peak (weekend morning) in case MySQL rebind requires a container
restart.