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
{{ message }}
Repository navigation
Session invalidation when scaling Kratos replicas in Kubernetes
#4303
Session invalidation when scaling Kratos replicas in Kubernetes
Environment
Ory Kratos version: v1.3.1
Kubernetes deployment using official Helm chart (version 0.50.7)
Database: PostgreSQL
Service Mesh: Linkerd
CNI: Flannel
External Access: Cloudflare Tunnels (no K8s Ingress)
Deployment Scale: 3 replicas
Description
When scaling Ory Kratos from 1 to multiple replicas in a Kubernetes environment, sessions become invalid intermittently. While the root cause is not yet determined, one hypothesis is that it might be related to session cache inconsistency between replicas, though this is purely speculative and needs validation.
Steps to Reproduce
Deploy Ory Kratos using the official Helm chart
Configure custom NGINX proxy for HTTPS termination
Scale deployment to multiple replicas
Authenticate user through frontend application
Make subsequent API calls using the obtained session
Current Behavior
With 1 replica: Sessions work perfectly
With >1 replicas: Random "No valid session found" errors occur during:
Direct Frontend-to-Kratos via Cloudflare Tunnel and NGINX Proxy obtained ory_kratos_session (no issue)
Subsequent internal Service-to-Service communication via internal DSN of Kratos Public / Admin Service API forwarding the initially obtained ory_kratos_session (no valid session found error comes up)
Expected Behavior
Sessions should remain valid regardless of which replica handles the request.
Configuration
# Relevant parts of values.yamlreplicaCount: 3deployment:
annotations:
linkerd.io/inject: enabledkratos:
config:
serve:
public:
base_url: https://auth.example.org/cors:
enabled: trueallowed_origins:
- https://app.example.orgallowed_methods:
- POST
- GET
- PUT
- PATCH
- DELETEallowed_headers:
- Authorization
- Cookie
- Content-Typeallow_credentials: truesession:
cookie:
persistent: truelifespan: 24h
Service architecture:
Frontend -> Cloudflare Tunnel -> NGINX Proxy -> Kratos Public API (internal port 80)
Quart Microservices -> Internal cluster DNS -> Kratos Public & Admin APIs
- Public API: For session validation, user data retrieval
- Admin API: For privileged operations (internal only)
Additional Context
All services (including NGINX proxies) are replicated 3 times
Session is stored in PostgreSQL database
While all data is properly stored in PostgreSQL, the exact cause of session invalidation is unclear. The in-memory session caching hypothesis is just one possible explanation that needs investigation
No Kubernetes Ingress is used and shall not be used; all external traffic routes through Cloudflare Tunnels (thus configuring Ingress via Ory Kratos values.yaml is not an option)
Attempted Solutions
Implemented session affinity at the Service level:
Ensured proper pod distribution using topology spread constraints and anti-affinity rules
Questions
Has anyone successfully run Ory Kratos with multiple replicas in a Kubernetes environment? We're experiencing session invalidation issues when scaling beyond a single replica, and would greatly appreciate any insights or recommendations from the community regarding horizontal scaling of Kratos.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Session invalidation when scaling Kratos replicas in Kubernetes
Environment
Description
When scaling Ory Kratos from 1 to multiple replicas in a Kubernetes environment, sessions become invalid intermittently. While the root cause is not yet determined, one hypothesis is that it might be related to session cache inconsistency between replicas, though this is purely speculative and needs validation.
Steps to Reproduce
Current Behavior
Expected Behavior
Sessions should remain valid regardless of which replica handles the request.
Configuration
Service architecture:
Additional Context
Attempted Solutions
Questions
Has anyone successfully run Ory Kratos with multiple replicas in a Kubernetes environment? We're experiencing session invalidation issues when scaling beyond a single replica, and would greatly appreciate any insights or recommendations from the community regarding horizontal scaling of Kratos.
Relevant Links
Config files / Logs
Please advise what further config files and logs would be helpful, and I'll provide them.
All reactions