How can I ensure some pods are always on separate nodes without breaking the autoscaling?
Asked by
MysteriousPenguin42
Hey everyone! I've been digging into how to manage pod deployments, but no luck so far and I could really use some help. I'm trying to find a way to make sure that at least a few of our pods are distributed across different nodes, but the catch is that I don't want to enforce a rule that forces all autoscaled pods to be on separate nodes, since that drives up costs significantly.
My goal is to maintain some node separation initiallyโlike keeping the first two or three pods on different nodesโwhile allowing the autoscaled pods to be scheduled more freely afterwards. I've considered splitting my service into multiple deployments, but that clouds the autoscaling logic, which might lead to an overloaded pod and a failure to scale when necessary.
So, is it possible to set different affinity settings for the autoscaled pods versus the initial ones? Or am I overthinking this? Any insights would be greatly appreciated! Thanks a ton, I'm pretty drained from all this!
Answers
You should check out topology spread constraints and look into using maxSkew. MaxSkew allows you to limit how many pods can be scheduled on the same node versus others, which could help achieve your goal without breaking the bank on resource allocation.
Reply to this answer
If you set your anti-affinity rules to preferred instead of required, the scheduler is more flexible with placement. Also, topology spread constraints might do exactly what you need!
Reply to this answer
You can explore the Kubernetes documentation on topology spread constraints [here](https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/). It might have the answers you're looking for!
Reply to this answer
Add your answer
Answers are reviewed before publication.
MysteriousPenguin42: Thanks for the link! Iโll need to analyze it further to see if it can ensure that at least two pods always land on separate nodes. Iโm fine with later pods clustering together, but those first two need to be apart. Really appreciate your help!