URL-based Ingress routing for versioned microservice APIs

PCD By islever Editorial Last updated

Short answer

A Use an Ingress that matches the API's URL and routes each version's requests to the appropriate Kubernetes Service backend.

Question

You are designing an application that consists of several microservices. Each microservice has its own RESTful API and will be deployed as a separate Kubernetes Service. You want to ensure that the consumers of these APIs aren't impacted when there is a change to your API, and also ensure that third-party systems aren't interrupted when new versions of the API are released. How should you configure the connection to the application following Google-recommended best practices?
  1. Use an Ingress that uses the API's URL to route requests to the appropriate backend. Correct Answer
  2. Leverage a Service Discovery system, and connect to the backend specified by the request.
  3. Use multiple clusters, and use DNS entries to route requests to separate versioned backends.
  4. Combine multiple versions in the same service, and then specify the API version in the POST request.

Key Takeaways

Protecting microservice API consumers from version changes depends on a stable URL-based entry point in GKE. An Ingress that matches on the API's URL and forwards to a named backend Service is the correct choice, because it lets v1 and v2 run side by side while consumers and third parties keep dialing the same address. Service discovery, multi-cluster DNS, and version markers inside POST bodies each push the change onto the caller instead of the routing layer.

Expert Analysis

API Gateway provides centralized management for microservice APIs with auth, routing, and rate limiting in one place. Apigee (B) is for enterprise platforms. Cloud Endpoints (C) handles individual APIs. IAP (D) secures app access.

The deciding constraint here is that consumers hold one stable entry point while each microservice runs as its own Kubernetes Service, so the routing layer must absorb version changes behind a single address. That is exactly what A. Use an Ingress that uses the API's URL to route requests to the appropriate backend delivers: an Ingress object in GKE matches on host and path portions of the incoming URL and forwards to a named backend Service, so /v1/orders can point at one Service and /v2/orders at another without either consumer changing how it dials in. URL-based matching is the mechanism that keeps third-party systems uninterrupted: the caller keeps requesting the same base URL and the same path prefix it was issued, while you repoint the matching rule at a new backend Service when a version rolls out.

Option B. Leverage a Service Discovery system, and connect to the backend specified by the request puts the version decision inside every consumer. Each client must now resolve, select and hold a live endpoint, and a service-discovery lookup changes its result the moment you scale or reschedule the backing Pod — so an API contract change propagates as a client-side code change, which is precisely the consumer impact this design is meant to prevent. It also breaks the third party: the external system's request must already name the correct backend, so releasing v2 requires the external party to be reconfigured.

Option C. Use multiple clusters, and use DNS entries to route requests to separate versioned backends multiplies the problem across cluster boundaries. The DNS record still has to be rewritten for every version cutover, and DNS changes propagate on TTL, which means consumers and third parties keep resolving the stale cluster until the record expires — an interruption the URL-matched Ingress never causes because the public name never moves. Running one Service per microservice already gives you per-version isolation; duplicating it into a second cluster adds operational surface without protecting the consumer contract.

Option D. Combine multiple versions in the same service, and then specify the API version in the POST request is the sharpest failure. Forcing v2 consumers to send a version marker inside every request means the released contract itself differs, so existing third-party clients sending unmarked or v1-tagged POST bodies are rejected or misrouted at the moment you release. Co-locating versions in one Service also removes the routing indirection that would let you redirect traffic between them.

One mechanism this design relies on but does not state: an Ingress routes on the URL path only after Kubernetes resolves that path to a serviceName in its rules, and the Service it names selects Pods through label selectors — so "API version" in the URL is a routing key, not a contract change. Give each version its own Service with labels like app=orders, version=v2, then a rule sending /v2/ to orders-v2 lets you promote traffic by editing one Ingress rule while both Services stay live, which is how new versions ship without touching consumer configuration. Google's GKE guidance places exactly this Ingress-based path routing in front of versioned Services rather than exposing cluster-internal addresses or requiring client-side discovery.

Exam Strategy

When a question promises that existing consumers and third parties must keep working unchanged, reject any option that moves the version decision into the client — discovery lookups, DNS rewrites, or extra fields in the request body all signal that. Look for the layer that matches on host/path and forwards to a named backend, since a stable URL plus a repointed rule is the standard GKE pattern for shipping a new API version without touching callers.

Practice All PCD Questions

Access 84 questions with complete answers and detailed explanations.

View Full PCD Practice Test →

← Back to PCD Study Guide