Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/toolhive/guides-k8s/run-mcp-k8s.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,35 @@ backends.

:::

### Session affinity for proxy replicas

Clients connect to the proxy runner through its Service. When you run more than
one proxy replica (`spec.replicas > 1`), the `spec.sessionAffinity` field
controls whether that Service routes repeated connections from the same source
IP to the same proxy pod:

- `ClientIP` (default) - routes connections from the same source IP to the same
proxy pod. Because MCP transports (SSE and Streamable HTTP) are stateful, this
keeps a client's connections on the replica that holds its in-memory session.
- `None` - load-balances each connection freely across proxy pods.

```yaml title="MCPServer resource"
spec:
replicas: 2
# highlight-next-line
sessionAffinity: None # default is ClientIP
```

Affinity only influences routing; it does not move session state between pods.
`ClientIP` is also unreliable behind NAT or shared egress IPs, where many
clients share a source address. For reliable scaling, configure
[Redis session storage](./redis-session-storage.mdx#horizontal-scaling-session-storage)
so any proxy pod can serve any client rather than depending on affinity alone.

This client-facing affinity is separate from the backend session routing
described next, which controls how the proxy reaches backend pods when
`spec.backendReplicas > 1`.

### Session routing for backend replicas

MCP connections are stateful: once a client establishes a session with a
Expand Down