
At trivago, more than 200 engineers work on 100+ microservices running on Google Kubernetes Engine across three regions. At any given moment there are over 100 open pull requests on our website application’s repository alone, and a similar number across the backend services. The team has a need to test changes before they go live: the author, a reviewer, a QA engineer, sometimes a product manager.
We serve that need with preview environments. A preview environment is a short-lived deployment of the changed service, one per pull request, reachable under its own URL. It appears when the PR opens and disappears when the PR merges or closes.
Today we run 600+ of these environments on Kubernetes, and most of the time most of them cost us nothing, because they are scaled to zero. A preview is typically used for two to three hours per working day. The rest of the time it exists only as manifests in Git and a few Kubernetes objects, not as running pods.
This post covers the decisions behind that setup: why we moved previews to Kubernetes, why the obvious ways of running them there were too expensive, why we rejected Knative, how KEDA’s HTTP add-on ended up on our request path, and why every preview gets two URLs instead of one. Jan Wozniak (KEDA maintainer, Kedify) and myself gave a talk at KubeCon 2026 in Amsterdam, which you can watch on YouTube. If you want to build the same thing yourself, I maintain a public step-by-step walkthrough that runs on a local Minikube cluster; this post stays on the “why” and links there for the “how”.
Where we started
Preview environments were not new to us. Our frontend has had them for years on Google Cloud Run, Google’s serverless container platform. Cloud Run charges per request and scales to zero on its own, which made frontend previews almost free: 600+ of them cost us less than 100 Euro per month.
The backends were a different story. They run on GKE with staging and production environments, and no previews at all. Backend teams shared staging, with the problems every shared staging has. Changes queued behind each other. A test failure could come from your change or from whatever someone else had deployed an hour earlier. When something broke, finding out whose change broke it took longer than the fix.

We could have put the backends on Cloud Run too. We went the other way, for two reasons. First, Cloud Run gets expensive at production scale; the pay-per-request model that makes idle previews cheap works against you on services that are never idle. Second, and more important for day-to-day work, running two platforms split everything: monitoring, logging, and deployment tooling all existed twice, once for Cloud Run and once for Kubernetes.
So the goal became: unify on Kubernetes. And the way in was to solve preview environments for the backends first. If previews worked well on Kubernetes, the frontend could migrate without giving anything up, and both problems would be solved by the same machinery.
Why “just run them on Kubernetes” was not an option
The naive version is easy: render manifests per PR, apply them, delete them on merge. We did the math on what that costs.
Our frontend previews alone would mean 600+ environments at roughly two pods each, so about 1,200 pods, each requesting around 1 CPU and 1 GB of memory, running around the clock. That would have cost more than the production workloads themselves. Paying production prices for environments that are actively used for two to three hours per working day was not something we could justify.
The first idea everyone has is a schedule: scale previews down at night and up in the morning. We dropped it quickly. Our engineers work across time zones and do not follow a 9-to-5 pattern, and a preview that is asleep exactly when a reviewer clicks the link is worse than no preview, because it costs trust.
What we actually needed was behavior Cloud Run already had: scale to zero when idle, and wake up when a request arrives, without losing that request. Kubernetes does not do this out of the box. The Horizontal Pod Autoscaler historically cannot go below one replica, and although native scale-to-zero for the HPA is arriving with Kubernetes 1.36, that still leaves the harder half of the problem: something has to catch the HTTP request that arrives while the deployment is at zero, trigger the scale-up, and deliver the request once a pod is ready.
Why not Knative
Knative is the standard answer for scale-to-zero HTTP workloads on Kubernetes, and we looked at it seriously. We decided against it for three reasons.
First, Knative brings its own workload model. A Knative Service is not a plain Deployment, and we wanted preview environments to use the same standard Kubernetes manifests as staging and production. The whole point of the migration was to stop maintaining parallel stacks; adopting a different deployment model just for previews would have rebuilt the split we were trying to remove.
Second, Knative routes traffic only to healthy pods. That sounds like a feature, and for production it is. For previews it gets in the way: when a preview is broken, you want to reach it and see how it is broken, not get silently routed somewhere healthy. Later in this post there is an incident report about exactly that failure mode.
Third, Knative supports a single ingress, and we run two Istio ingress gateways, one public and one private. Preview environments live behind the private one, and we were not willing to restructure our ingress layer around a preview tool.
From pull request to running environment
Before the scaling story, here is what actually happens when an engineer opens a pull request.
One decision shapes everything else: we deploy only the changed service. If you open a PR against the booking service, the preview contains the booking service built from your branch, and nothing else. Every dependency resolves to its staging instance. With 100+ microservices, deploying a full copy of the platform per PR would multiply both the cost and the number of things that can flake. Deploying one service against stable staging dependencies keeps the environment small and keeps failures attributable to the change under test.
The pipeline is GitOps end to end:
- Every PR triggers a GitHub Actions workflow. It builds the Docker image and pushes it to GCP Artifact Registry.
- The workflow renders the Kubernetes manifests with Helm and Skaffold, injecting the PR number and the short commit SHA so that names, namespaces and URLs are unique per PR and per commit.
- The rendered manifests are committed to a GitOps branch, one directory per PR:
preview/1247/,preview/1248/, and so on. - A single ArgoCD
ApplicationSetwatches for pull requests and creates one ArgoCDApplicationper PR, pointed at that PR’s directory. - When the PR merges or closes, the generator removes the
Application, ArgoCD prunes the resources, and the workflow cleans up the directory.

The ApplicationSet is the piece that removes all environment lifecycle management from humans. Simplified:
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
name: booking-preview
namespace: argocd
spec:
goTemplate: true
syncPolicy:
preserveResourcesOnDeletion: false
generators:
- pullRequest:
# How often ArgoCD polls GitHub for new or closed PRs
requeueAfterSeconds: 90
github:
owner: trivago
repo: booking-service
labels:
- preview # only PRs labeled by the CI workflow
template:
metadata:
name: preview-booking-{{.number}}
spec:
project: default
source:
repoURL: https://github.com/trivago/booking-service.git
targetRevision: gitops-preview
path: preview/{{.number}}
destination:
server: https://kubernetes.default.svc
namespace: preview-booking-{{.number}}
syncPolicy:
automated:
prune: true
selfHeal: trueOne ApplicationSet per service manages every preview of that service. Nobody creates or deletes environments; opening and closing pull requests is the entire interface.
Scale to zero with the KEDA HTTP add-on
The missing piece was the Cloud Run behavior: idle previews at zero, instant wake-up on traffic. We were already running KEDA in production for a different problem, scaling Kafka consumers on consumer lag, which we wrote about in From Always-On to On-Demand: Scaling Kafka Sinks with KEDA. KEDA is a CNCF graduated project with 70+ scalers, and its core trick is exactly the one HPA lacks: it can take a workload to zero replicas and bring it back.
But HTTP is a special case. A Kafka scaler can watch consumer lag from the outside; the queue holds the messages while pods start. HTTP has no queue. If the deployment is at zero when a request arrives, something has to hold that request, and that something must sit in the request path.
That is what the KEDA HTTP add-on does. It puts an interceptor, an L7 proxy, in front of the workload. When a request arrives for a scaled-to-zero preview, the interceptor holds it, the pending request count becomes the scaling metric, KEDA scales the deployment from zero to one, and the interceptor releases the request once the pod is ready. The person clicking the link sees a slow first response instead of an error. When traffic stops, a cooldown passes and KEDA takes the deployment back to zero.

Each preview declares this behavior with an HTTPScaledObject, rendered by the same Helm chart as everything else. Simplified, with each field explained:
apiVersion: http.keda.sh/v1alpha1
kind: HTTPScaledObject
metadata:
name: booking
namespace: preview-booking-1247
spec:
hosts:
# The interceptor identifies the target workload by Host header
- pr-1247.booking.internal.trv.cloud
replicas:
min: 0 # scale to zero when idle; this is the entire point
max: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: booking
service: booking
port: 80
scaledownPeriod: 300
scalingMetric:
requestRate:
granularity: 1s
targetValue: 1
window: 1mhostsis how the interceptor routes. It maps the incoming Host header to the right deployment, which is why every preview needs a unique hostname.replicas.min: 0enables scale to zero.maxcaps how far a single preview can scale out; previews serve a handful of humans and a test suite, not production traffic.scaleTargetRefpoints at the deployment and the service that fronts it, so the interceptor knows where to forward released requests.scaledownPeriodis the idle window. Too short and the preview flaps while someone reads a page; too long and you pay for idle pods.scalingMetric.requestRatedrives scaling between one andmaxonce the workload is awake. For previews this rarely matters; the interesting transitions are zero to one and back.
Why every preview has two URLs
This section exists because of a production incident.
Our first iteration gave each preview one URL. It pointed at the Kubernetes Service, which routes to ready pods. Integration tests ran against it, they passed, PRs merged. Then one deployment to production started crashing on startup. The pipeline for the PR that caused it was green. The integration tests had passed.
We reopened the merged PR and dug in. One commit in that PR made the service exit with a non-zero code on boot. The preview environment had received that commit, and Kubernetes had done a rolling update: it started a new pod, the new pod crashed, so Kubernetes kept the old pod running and never shifted traffic. Every request, including our integration tests, was served by the previous, healthy version. The tests validated code that was about to be replaced. The crashing code shipped.
Kubernetes was doing its job. Rolling updates are designed to protect traffic from unhealthy pods. But a preview environment has a different goal than production: we do not want to be protected from the broken version, we want to hit it. Our setup could catch bugs in business logic. It was structurally blind to a service that failed to start.
Note that this is the same property that made us walk away from Knative: routing that always prefers healthy pods is safety in production and blindness in testing.

The fix was to give every preview a second URL:
- The PR URL,
pr-1247.booking.internal.trv.cloud, routes through the KEDA interceptor to ready pods. This is the one for humans: it always shows something working, and it is the URL that wakes the environment from zero. - The commit URL,
pr-1247-abc12ef.booking.internal.trv.cloud, carries the short SHA of the latest commit and routes only to pods running exactly that commit. If those pods are crash-looping, requests to the commit URL fail, and that failure is the signal. Integration tests run against the commit URL, after an initial request to the PR URL to wake the environment and a wait-for-availability check.
Both URLs live in one Istio VirtualService. The commit route matches first because it is more specific:
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: booking
namespace: preview-booking-1247
spec:
gateways:
- istio-system/private-gateway
hosts:
- pr-1247.booking.internal.trv.cloud
- pr-1247-abc12ef.booking.internal.trv.cloud
http:
# Commit URL: straight to the pods of this exact commit, no interceptor
- match:
- authority:
prefix: pr-1247-abc12ef
route:
- destination:
host: booking
subset: abc12ef
port:
number: 80
# PR URL: through the KEDA interceptor, which scales from zero
- match:
- authority:
prefix: pr-1247.
route:
- destination:
host: keda-add-ons-http-interceptor-proxy.keda-http-addon.svc.cluster.local
port:
number: 8080The subset is defined by an Istio DestinationRule that selects pods by their version label, which our Helm chart sets to the short SHA:
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: booking
namespace: preview-booking-1247
spec:
host: booking
subsets:
- name: abc12ef
labels:
version: abc12efEvery push renders a new commit URL, so tests always target the code that was just pushed, never a leftover pod from the previous commit.
Living with a proxy on the request path
There is one property of this design you should not gloss over, and Jan Wozniak spent a good part of our KubeCon talk on it: the HTTP add-on is not like other KEDA scalers. A Kafka or Prometheus scaler observes from the outside; if it fails, your application keeps running at its current scale, and you fix the scaler at your leisure. The HTTP interceptor proxies every request. If it fails, traffic stops. Adopting it means adopting a new piece of critical infrastructure, and it deserves the same readiness gates, timeouts, resource headroom and observability as your ingress. Cold starts are user-facing too: when scale-from-zero triggers, a person is looking at a spinner, so pod startup time directly becomes user experience.
We first tried this in a proof of concept in December 2023. The upstream add-on at the time was missing features we needed and was not stable at the scale we were aiming for, so we went to production on Kedify’s distribution of the add-on, built by KEDA maintainers, Jan among them. The capability that mattered most to us is its failure mode: if the interceptor becomes unhealthy, traffic is rewired to bypass it and the workload falls back to a static replica count, then autoscaling resumes when the interceptor recovers. The proxy on the data path stops being a single point of failure and degrades to “no scale-to-zero for a while”, which for preview environments is a perfectly fine worst case.
What we ended up with
The plan from the start was that solving backend previews would unlock the frontend migration, and that is how it played out. Both frontend and backend previews now run on Kubernetes, the Cloud Run setup is retired, and previews, staging and production share one platform with one set of monitoring, logging and deployment tooling.
On cost, the honest framing is avoided spend rather than a measured saving, since we never ran the always-on variant. The arithmetic: 600+ environments at about two pods each would be roughly 1,200 always-on pods, or about 28,800 pod-hours per day. With previews used two to three hours per working day and scaled to zero otherwise, the same fleet consumes a small fraction of that, and effectively nothing on weekends.
For engineers, the workflow is: open a PR, wait for the pipeline, and find two URLs on the PR. Click the PR URL to look at the change; point tests and automation at the commit URL. Merge, and everything you just used is gone.
What we would tell you to do differently
Design the commit URL in from day one. We added it after an incident that reached production. The failure mode it covers, tests passing against the old version during a rolling update, stays invisible until the day it reaches production.
Deploy only the changed service. Cost scales with the number of open PRs either way; keeping each environment to one service keeps that scaling linear and keeps test failures attributable.
Treat the interceptor as production infrastructure. Scale-to-zero savings are real only with guardrails: readiness gating, timeouts, observability and sane defaults. A proxy on the request path fails differently than a metrics poller.
Skip the cron detour. If your first instinct is scheduled scale-down, ours was too. Developers do not keep office hours, and wake-on-request is the feature that makes previews trustworthy.
If you want to build this yourself, the k8s-preview repository walks through the full setup on Minikube: ArgoCD, the ApplicationSet, the KEDA HTTP add-on, Istio routing and the two-URL scheme, with working manifests and a demo app. The KubeCon talk covers the same story with a live demo. And if your idle workloads are event-driven rather than HTTP, the Kafka sinks post is the companion piece: same idea, different scaler.

Follow us on