D
Dokploy6mo ago
max.d

Zero downtime for NextJS

Hey guys I'm having difficulty setting up 0 downtime for a NextJS app with 4 Replicas. This is my config: Health Check
{
"Test": [
"CMD",
"curl",
"-f",
"http://localhost:3000"
],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 30000000000,
"Retries": 3
}
{
"Test": [
"CMD",
"curl",
"-f",
"http://localhost:3000"
],
"Interval": 30000000000,
"Timeout": 10000000000,
"StartPeriod": 30000000000,
"Retries": 3
}
Update Config
{
"Parallelism": 1,
"Delay": 10000000000,
"FailureAction": "rollback",
"Order": "start-first"
}
{
"Parallelism": 1,
"Delay": 10000000000,
"FailureAction": "rollback",
"Order": "start-first"
}
Additional Traefik config modification with sticky sessions
services:
web-3d327d:
loadBalancer:
servers:
- url: http://web-3d327d:3000
passHostHeader: true
sticky:
cookie:
httpOnly: true
services:
web-3d327d:
loadBalancer:
servers:
- url: http://web-3d327d:3000
passHostHeader: true
sticky:
cookie:
httpOnly: true
After deploy NextJS serves new HTML but is unable to find new static files. I initially thought that this is due to sessions being balanced between old/new replicas incorrectly, but sticky sessions should've taken care of that. What am I missing?
2 Replies
𖤬𝔫𝔡𝔶
^ bump, having the same issue @Siumauricio, after deploying the load balancer makes it so some users are loading the backend from an older container, we have this Traefik config:
http:
middlewares:
# Rate-limit middleware
rate-limit:
rateLimit:
average: XX # Requests per second on average
burst: XX # Maximum requests allowed to burst
period: Xs # Time period for the average calculation
sourceCriterion:
ipStrategy:
depth: 0 # Use the client IP directly

# Large upload middleware
large-upload:
buffering:
maxRequestBodyBytes: XXXXXXXXXX # Size in bytes
memRequestBodyBytes: XXXXXXXXX # Threshold before using disk

routers:
[service-name]-router-XXXX:
rule: Host(`example.com`)
service: [service-name]-service-XXXX
middlewares:
- redirect-to-https
entryPoints:
- web

[service-name]-router-websecure-XXXX:
rule: Host(`example.com`)
service: [service-name]-service-XXXX
middlewares:
- rate-limit
- large-upload
entryPoints:
- websecure
tls:
certResolver: letsencrypt

services:
[service-name]-service-XXXX:
loadBalancer:
servers:
- url: http://[internal-service-name]:XXXX
passHostHeader: true
sticky:
cookie:
name: example_sticky
secure: true
httpOnly: true
sameSite: "lax"
http:
middlewares:
# Rate-limit middleware
rate-limit:
rateLimit:
average: XX # Requests per second on average
burst: XX # Maximum requests allowed to burst
period: Xs # Time period for the average calculation
sourceCriterion:
ipStrategy:
depth: 0 # Use the client IP directly

# Large upload middleware
large-upload:
buffering:
maxRequestBodyBytes: XXXXXXXXXX # Size in bytes
memRequestBodyBytes: XXXXXXXXX # Threshold before using disk

routers:
[service-name]-router-XXXX:
rule: Host(`example.com`)
service: [service-name]-service-XXXX
middlewares:
- redirect-to-https
entryPoints:
- web

[service-name]-router-websecure-XXXX:
rule: Host(`example.com`)
service: [service-name]-service-XXXX
middlewares:
- rate-limit
- large-upload
entryPoints:
- websecure
tls:
certResolver: letsencrypt

services:
[service-name]-service-XXXX:
loadBalancer:
servers:
- url: http://[internal-service-name]:XXXX
passHostHeader: true
sticky:
cookie:
name: example_sticky
secure: true
httpOnly: true
sameSite: "lax"
max.d
max.dOP2mo ago
I've created a ticket here: https://github.com/Dokploy/dokploy/issues/1487 It looks like Traefik is not able to route requests properly. Cookie is set but requests are still routed via WRR.
GitHub
Unable to use sticky sessions in traefik · Issue #1487 · Dokploy/do...
To Reproduce I have an application running via Dockerfile. I have 4 replicas and application config modified as follows: services: development-experiments-z8rb1q-service-30: loadBalancer: sticky: c...

Did you find this page helpful?