Kubernetes has transformed container orchestration, and Google Kubernetes Engine (GKE) provides a powerful, managed platform for deploying and scaling containerised applications. While GKE offers strong capabilities for service discovery and load balancing, there are still limitations on applying custom processing logic to traffic before it reaches the workloads.
This is whereย Service Extensionsย come into play, providing a compelling solution to customise and enhance the Cloud Load Balancing with the GKE Gateway API (Note: This is a kubernetes feature and unrelated to Google Cloudย API Gatewayย Service).
What are Service Extensions in GCP?
Service Extensionsย enables users to inject custom logic directly into the data path, enabling advanced modifications to traffic that flows through the load balancer. It's like a pipeline where you can insert your own code at various stages to manipulate the requests and responses without impacting the backends.
There are two primary types of Service Extensions:
- Plugins:ย These allow for inline custom code insertion directly within the networking data path. Built using WebAssembly (Wasm) and the Proxy-Wasm ABI, plugins run as Wasm modules on a Google-managed sandbox infrastructure. They are designed for low-latency operations and are ideal for light-weight logic that needs to execute very close to the data plane.
- Callouts:ย These enable Cloud Load Balancing to make gRPC calls to external services โ either Google-managed services or user-managed servicesย (including those running on GKE Pods). Callouts offer greater flexibility as they can reuse existing software and have fewer runtime restrictions, making them suitable for more complex logic that might require external data or state.
The GKE team recently announced preview support for Service Extensions in theย Gateway API. This allows users to manipulate HTTP headers and payloads for requests and responses and even control traffic routing, all without impacting the existing backend service selections or security policies.
Types of GKE Gateway API Service Extensions
GKE Gateway controller currently supports two types of Callouts Service Extensions, each designed for specific functionalities:
GCPRoutingExtension: This extension type is focused onย controlling traffic routing. It's ideal for scenarios where you need to direct traffic to different backend services or apply custom routing logic.
GCPTrafficExtension: This extension type allows you toย change the headers and payloads of requests and responses. It operates without affecting backend service selection or security policies, making it perfect for data transformation and enrichment.
Configure Service Extensions in GKE Gateway API
To explore the service extension feature in GKE, you need a GKE cluster with version 1.33 or later andย Gateway APIย enabled. Also, review the currentย Restrictions and limitationsย of Gateway Service Extensions in GKE before testing this feature.
Deploy a Gateway
To configure a Service extension, you must first deploy a Gateway resource or verify that the existing Gateway resource uses a supported GatewayClass. For details on supported load balancers, refer toย Google Cloud Service Extension compatibility with GatewayClasses.
- Apply the below manifest to deploy a simple regional application load balancer gateway.
Deploy a sample store backend application
- Apply the below manifest to deploy the sample backend application andย HTTPRouteย resources. The HTTPRoute specifies the routing behaviour of HTTP requests from a Gateway listener to the backend application.
- Send a sample request to the gateway API IP address to test the backend response.
The output is similar to the following:
Deploy a backend callout service
A callout service implements the custom logic for Gateway Service Extensions in GKE. The Load Balancer invokes the backend applications based onย GCPTrafficExtensionย orย GCPRoutingExtensionย configurations, to modify or route traffic.
If you are deploying a callout service in the GKE cluster, you must meet all the requirements mentioned in theย limitations.
- Generate a self-signed certificate for the callout service backend usingย mkcertย or any other method. This is necessary because you must use HTTP2 as it's
appProtocolย which requires end-to-end TLS.
- Create a K8S Secret with the self-signed cert.
- Apply the manifest below to deploy the sample callout application. For more code samples, refer to theย service-extensionsย GitHub repository.
- The sample application performs a basic header modification for both the request and response. Refer toย service_callout_example.pyย for further details, and you can develop your own application based on the business requirements.
Configure the Service Extensions
You can configure either aย GCPRoutingExtensionย or aย GCPTrafficExtensionย to customize your traffic flow.
- Apply the manifest below to create aย
GCPRoutingExtensionย resource, and the load balancer will call the extension service app for the requests sent to the pathยrouteextensionย and then forward it to the backend store application.
- Update theย
HTTPRouteย resource withยservice-extensions.comย host since the callout service performs a host header modification before forwarding the requests to the store app.
- The Gateway API controller may take a few minutes to sync the changes. Use the commandย
kubectl describe gateway GATEWAY_NAMEย to confirm that theยGCPRoutingExtensionย is bound to the Gateway.
- The output shows the annotations, which GKE uses to store the links between the Gateway and the underlying Google Cloud resources. Theย
networking.gke.io/lb-route-extensionsย annotation confirms the binding of the gateway to theยGCPRoutingExtension. - Now test the traffic to theย
routeextensionย path by replacingยGATEWAY_IP_ADDRESS.
- The output resembles the following, and you can notice the changes in theย
host_headerย within the response.
You can useย GCPTrafficExtensionย to implement custom request and response logic, sophisticated routing, transformations, and security policies.
- Apply the manifest below to create aย
GCPTrafficExtensionย resource, and the load balancer will call the extension service app for the requests sent to the pathยtrafficetension. You can customize and control the load balancer invocation to the callout application by updating theยsupportedEventsย .
- Now test the traffic to theย
trafficextensionย path by replacingยGATEWAT_IP_ADDRESS.
- The output resembles the following, and you can notice the customer response header changes inย
helloย and the response body is removed.
Sample Pod logs:
Conclusion
GCP Service Extensions for GKE Gateway API represent a significant advance in how platform teams can manage, shape, and secure traffic at the ingress layer. Whether you need to enforce custom authentication, manipulate headers, perform traffic shaping, or integrate with external systems, Service Extensions enable you to do so declaratively and scalably.
Although it is still in preview, this presents an excellent opportunity to explore Service Extensions, test them in non-production environments, and develop reusable extension services tailored to your platform requirements.
If you are considering a PoC, you are not alone.ย DoiTย is here to help you assess, plan and migrate with a strong focus on your business outcomes. With over 100 senior cloud experts specializing in crafting customized cloud solutions, our team is ready to help you navigate this process smoothly and optimize your infrastructure to ensure compliance and meet future demands efficiently.
Our experts are ready to provide you with strategic guidance and technical expertise every step of the way. Letโs discuss what makes the most sense for your company during this policy enforcement phase, ensuring your cloud infrastructure is robust, compliant, and optimized for success.ย Contact us today.






















