svenstaro/miniserve

Running with multiple replicas

ffzzhong opened this issue · 6 comments

hi, I plan to run miniserve in k8s with multiple replicas behind a nginx ingress controller, in this pattern, multiple replicas make the service more robust and there will be automatic load balancing inside the cluster.

I found if I run only 1 replica, everything works fine, but if I run with multiple replicas, say 2 or 3, then page sometimes rendered without CSS, it throws Failed to load resource: the server responded with a status of 404 () because it's trying to look for the https://my.service.domain/xxxxxxxx static CSS file, I guess this path is only available on one replica but not all of them.

my entrypoint is straightforward and easy, just following the guide, /app/miniserve /data-folder

Am I missing some configuration? as I think it could be a typical use case that running multiple replicas, Any suggestion about how to make it work?

The static CSS file is inside the binary. It's not a real file and as such should exist in all instances. miniserve is entirely stateless and should as such be an ideal server to run for multiple replicas. I'm actually pretty confused why it would sometimes work and sometimes not.

Depending on what the issue and how you run it and how you're accessing it, it might help to use --route-prefix.

ahti commented

I think this is due to miniserve creating a random route for css and favicon on each launch (config.rs:196...), so different instances disagree on what the route should be. I would suggest switching to a .well-known/miniserve/... route for those.

@svenstaro actually I had already tried adding the --route-prefix, also configured ingress/livenessprobe/readinessprobe accordingly, the instances launched successfully but still got the same issue
the root cause might be like what @ahti mentioned?

Yes, that's very likely the cause. I'll look at it soon.