Laravel Cloud runs on AWS, specifically Amazon's managed Kubernetes offering: EKS. We pay for nodes by the hour, so we're incentivized to run the fewest nodes we can while still operating a reliable, resilient service.
By default, Kubernetes doesn't help us keep our node count down. For example the scheduler, when picking what node to put a new pod on, prefers to pick nodes with lower resource use.
// Spread pods across nodes
Over time, Kubernetes tries to spread pods evenly. We want the opposite. We want to pack pods tightly so it's easier to remove nodes when they're no longer in use.
// Pack pods onto fewer nodes
Tuning the scheduler
In Laravel Cloud, pods are being created and destroyed all of the time. Customers deploy new apps, delete old ones, and autoscaling is constantly tweaking replica counts. This churn results in lots of opportunities for the Kubernetes scheduler to spread pods out.
The good news is that this is just the scheduler's default behavior, and we can change it by setting a different scoringStrategy. We can get our desired outcome by using type: MostAllocated.
MostAllocated favors nodes where resources have already been allocated, provided the pod will fit. The bad news, at least for us, is that this setting was only made available in EKS in August 2026. We migrated to it straight away, but before August we invested lots of time into a custom operator that did this work for us.
This is great for new pods, but what about pods that are already running? As apps scale down, we can still end up with a node like this:
One pod happily doing its work on a mostly empty node. We want to move it and shut the node down, but this pod could be the only replica serving a customer's application. We have tens of thousands of single-replica apps in production today, they're a great choice for small side projects and internal tools that don't need to be up 100% of the time.
The problem is that moving them requires care.
Moving single-replica workloads without downtime
If we killed a nearly-empty node and relied on Karpenter, the software we use to manage our clusters, to find the pod a new home the following sequence of events would happen.
From Kubernetes' perspective, this went well. node-a is gone and we found a new home for the pod on node-b. From the customer's perspective, this went very poorly.
I'd usually recommend at least two replicas for apps that need to be available. If one goes away, the other can keep serving. But we wouldn't be a great platform if we forced customers to pay for two replicas just so we could do maintenance on our clusters.
Kubernetes already has a way to replace a pod without downtime: a rolling update waits for a new pod to become ready before stopping the old one. We don't need a new pod image to trigger a rolling update, either. We can do it by adding a benign annotation to the pod template. So when a node is marked for deletion, we block it until all of the pods have running replacements on other nodes.
This is how that would look if node-a had three single-replica applications running on it and we wanted to consolidate them onto a new node, node-b. Press "Delete node-a" to save us some money.
Now look at the Customer row: the old pod keeps serving while the replacement pulls its image and starts.
This allows us to consolidate nodes at will without causing downtime for single-replica applications. We scan our production clusters regularly for opportunities to consolidate, triggering this process when we find them.
What happens when too many pods move at once?
We've got a great solution for the nearly empty nodes. What about the nearly full ones? Another situation we see in practice is this one:
node-b has room for all the pods on node-a, so we can consolidate the two nodes. But moving every pod at once creates two problems:
- Many image pulls can compete for bandwidth and delay replacements.
- Several replicas of the same app can go offline together, cutting its serving capacity until their replacements are ready.
For applications with more than one replica, we don't "surge" their capacity in the same way we do for single-replica apps. We allow them to run at a lower capacity temporarily while we move things around instead. If the image pull is slow, apps stay in this lower capacity state longer.
For apps with more than one replica, we use a pod disruption budget to limit evictions to one replica per app at a time. Draining a node takes longer this way, but each app keeps more of its serving capacity during the move.
In this example, the pods moving off node-a all belong to one app. Different apps can still move at the same time.
Setting pod disruption budgets correctly
A pod disruption budget looks like this:
This says "At most one pod in the set of pods matched by the selector can be unavailable at the same time." It's also possible to replace maxUnavailable with minAvailable if you want to specify the constraint the other way around:
This says "One pod in the set of pods matched by the selector must always be available, no matter what." Tools like Karpenter read this to know what they can and can't do.
The problem we found is that there was no single config that worked for all customer applications, and it comes back to single-replica applications again. Let's consider the options:
minAvailable: 1doesn't work for single-replica apps because that single replica cannot ever be disrupted.maxUnavailable: 1doesn't work for single-replica apps because of that initial problem from before that we solved with a rolling update.minAvailable: 50%works for the single-replica app, protecting it during moves, but allows 50% of the capacity of larger apps to go offline at the same time.- You can't set
minAvailableandmaxAvailableat the same time, it has to be one or the other.
Even if there was some magical single config value we could use for all apps, we would still need to trigger a rolling update to get the zero-downtime moves on single-replica apps.
So we did what any discerning SRE team does when confronted with a Kubernetes problem that can't be solved with YAML: we put it in an operator.
This prevents Karpenter from killing single-replica apps too early by setting minAvailable: 1 on them. This gives us time to trigger a rolling update. Then for everything else, we allow maxUnavailable: 1 so as not to move too many things at once. It's fiddly, but it's been working well for us for several months now.
What Kubernetes could handle for us in the future
The Kubernetes proposal for an EvictionRequest API would give controllers a way to intervene before an eviction. The upstream tracker targets Kubernetes 1.38 for the alpha, which should drop by the end of this year.
That hook wouldn't start a replacement on its own, though. As the Karpenter discussion on replacement-first evictions explains, a controller would still have to start the new pod and wait for it to be ready. There's a proposal to support this in the Deployment controller that looks tentatively slated for Kubernetes 1.39.
So it looks possible that by 1.39 we won't need any of this custom machinery at all, single-replica deployments would be handled correctly by the tools we already use. We're excited to delete lots of code when that happens.
Obligatory warning about single-replica applications
Yes, we've put a lot of effort into making sure routine maintenance on Laravel Cloud doesn't disrupt your single-replica apps, but that doesn't mean they're always going to be available. Unplanned node problems, application-level bugs, and network problems we have no control over could take your application offline.
If your workload is business-critical, we recommend running at least two replicas so that you can handle unexpected failures.
What we'd tell another platform team
- Make sure you safely empty a node before you try to pack it. For us, that meant finding a way to move apps that have no spare replica and controlling the rate at which we move lots of pods at once.
- If you're managing Kubernetes clusters at scale, it is worth investing the time to get good at writing your own operators. Without that we would have had a very hard time solving this problem.
- Don't move fast if you don't need to. We use disruption budgets to protect app capacity, and a restart limit to keep apps from pulling too many images at once. Both of these are intentional speed limits we've put in place. It's okay for consolidation to be slow, it's not okay to disrupt customer applications.
Dense nodes are cheap right up until you have to empty them, but we've landed in a good place. This is just how we handle application workloads. How we handle databases is a whole other story. One for another time, though.