Connecting Apigee to GKE using headless services and Cloud DNS
The real architectural shift here is not just “connecting” two Google Cloud products, but removing an entire layer of duplicated L7 decision-making. By letting Apigee terminate requests and then resolve a pod directly, the design avoids pushing the same hostname and URI logic into both the API gateway and Kubernetes ingress or gateways. For practitioners, that matters because it trims configuration sprawl, reduces the chance of mismatched routing rules, and may lower latency compared with a double-proxy path.
The mechanism depends on three pieces working together: VPC-native GKE exposes pod IPs into the VPC, headless services publish DNS names that map to those pod IPs, and Cloud DNS makes those records visible beyond the cluster when configured with VPC scope. Apigee then uses DNS peering to query the same zone and target the backend directly. The practical implication is cleaner request flow, but also a tighter dependency on DNS correctness and pod churn behavior.
The proof-of-concept’s limits are important because they define where the idea can fail operationally. Cloud DNS imposes a default 10-second TTL in GKE integration, and that value is effectively controlled by the controller, not the operator. Higher TTLs risk stale pod targets after scaling; lower TTLs drive up query volume and cost. The secure-backend variant adds cert-manager and a mutating webhook with a reverse proxy sidecar, which preserves encryption but reintroduces extra moving parts the design initially sought to avoid.
VPC-native GKE clusters
Google Cloud recently introduced VPC-native GKE clusters. One of the interesting features about VPC native GKE clusters is that they use VPC IP alias ranges for pods and cluster IP services. While cluster IPs remain routable within the cluster only, pod IPs also become reachable from the other resources in your VPC (and from the interconnected infrastructure, like other VPCs or on-premises). Even if possible, clients shouldn’t reference pod IPs directly, as they are intrinsically dynamic. Kubernetes services are a much better alternative, as the Kubernetes DNS registers a well-known, structured record every time you create one.Kubernetes headless services
As introduced earlier, we need to create Kubernetes services (so DNS entries) that directly reference the pod IPs. This is exactly what Kubernetes headless services do — headless services reference pods just as any other Kubernetes service, but the cluster DNS binds the service DNS record and the pod IPs, instead of a dedicated service IP (such as ClusterIP services do). Now the question is how to make the internal Kubernetes DNS available also to external clients, so that they can query the headless service IP record and point exactly to the right pod IP (as the pod scales in and out).GKE and Cloud DNS integration
GKE uses kube-dns as the default cluster Domain Name Service, but optionally, you can choose to integrate GKE with Cloud DNS. While this is normally done to circumvent kube-dns scaling limitations, it also turns out to be very useful for our use-case. Setting GKE and Cloud DNS with a VPC scope allows clients outside the cluster to directly query the entries registered by the cluster in Cloud DNS.Apigee DNS peering
Apigee is the client that needs to communicate with the backend applications running on GKE. This means that, in the model we discussed above, it also needs to query the DNS entry to get in touch with the right pod. Living in a dedicated Google-managed project and VPC, Apigee needs to have DNS peering in place between its project and the user VPC. This way, it will gain visibility of the same DNS zones your VPC has visibility of, including the one managed by GKE. All of this can be easily achieved with a dedicated command.
Putting pieces together
- A VPC-native GKE cluster using Cloud DNS as its DNS service (configured in VPC scope)
- A backend application running on GKE (in form of one or more pods)
- A headless service pointing to the pod(s)
- Apigee configured to direct DNS queries to the user VPC
Exposing secure backends
You may also want to encrypt the communication end-to-end, not only from the client, to Apigee, but also up to the GKE pod. This means that the corresponding backends will expose certificates to Apigee. SSL/TLS offloading is one of the main tasks of ingress and gateway objects but this comes at the extra cost of maintaining an additional layer of software and defining L7 routing configurations in the cluster, which is exactly what we wanted to avoid and the reason why we came up with this proof of concept. Fortunately, other well-established Kubernetes APIs and tools can help you to achieve this goal. Cert-manager is a popular open source tool used to automate certificates lifecycle. Users can either create certificates from an internal Certificate Authority (CA) or request certificates from another CA outside the cluster. Through certificate objects and issuers, users can request SSL keypairs for pods running in the cluster and manage their renewal. While using cert-manager alone would be sufficient to make pods expose SSL certificates, it would require you to attach certificates manually to the pods. This is just a repetitive action that can certainly be automated using MutatingAdmissionWebhooks. To further demonstrate the viability of the solution, the second part of our exercise consisted in writing and deploying a Kubernetes mutating webhook. When you create a pod, the webhook automatically adds a sidecar container, running a reverse proxy that exposes the application TLS certificates (previously generated through cert-manager and mounted in the sidecar container as Kubernetes volumes).Conclusions, limitations and next steps
In this article, we proposed a new way to connect Apigee and GKE backends, so that you won’t have to perform L7 routing in both components. We think this will likely help you to save time (managing way less configurations) and to reach better performances. Collaborations are welcome. We really value your feedback and new ideas that may bring useful inputs to the project, so please give it a try. We released our demo as open source. You’ll learn more about GKE, Apigee, and all the tools and configurations we talked about above. We’re definitely aware of some limitations and conscious of some good work that the community may benefit from, moving forward:- When Cloud DNS is integrated with GKE, it sets for all records a default Time To Live (TTL) of 10 seconds. If you try to change this value manually, the Cloud DNS GKE controller will periodically override it, putting the default value back. Having high DNS values may cause clients to not be able to reach the pods that Kubernetes recently scaled. We’re working with the product team to understand if there is the chance to make this value configurable.
- On the other hand, using very low TTLs may largely increase the number of Cloud DNS queries, causing the increase of prices.
- We definitely look forward to adding support for other reverse proxies, such as Envoy or Apache HTTP Server. Contributions are always very welcome. In case you’d like to contribute but you don’t know where to start, don’t hesitate to contact us or to open an issue, directly in the repository
Enjoyed this article? Sign up for our newsletter to receive regular insights and stay connected.
