Gateway API
Understanding the Kubernetes Gateway API for advanced traffic routing, management, and service networking
Kubernetes Gateway API
The Gateway API is a next-generation networking API for Kubernetes that provides advanced traffic routing capabilities, moving beyond the limitations of Ingress resources for more complex networking scenarios. It offers a more expressive, extensible, and role-oriented approach to configuring service networking in Kubernetes, enabling sophisticated traffic management, multi-team collaboration, and better support for multiple protocols beyond HTTP.
Gateway API Overview
Core Concepts
- Expressive, role-oriented API: Designed with clear separation of concerns for infrastructure providers, cluster operators, and application developers
- Extensible resource model: Built to be extended with new capabilities and custom resources without breaking existing implementations
- Advanced routing capabilities: Supports sophisticated traffic management including header-based routing, traffic splitting, and multiple protocols
- Multi-tenant friendly: Enables secure sharing of networking resources across teams and namespaces with clear boundaries
- Improved role delegation: Allows cluster administrators to delegate specific networking responsibilities to application teams
Key Resources
- GatewayClass: Infrastructure configuration that defines a specific type of load balancing implementation (similar to StorageClass)
- Gateway: Deployment configuration that represents a specific instance of the load balancing infrastructure
- HTTPRoute: HTTP traffic routing rules that define how HTTP requests should be processed and forwarded
- GRPCRoute: gRPC traffic routing with protocol-specific features like service and method matching
- TCPRoute: TCP traffic routing for non-HTTP protocols requiring raw TCP handling
- TLSRoute: TLS traffic routing based on SNI (Server Name Indication) for TLS passthrough scenarios
- ReferenceGrant: Cross-namespace references that explicitly allow resources in one namespace to reference resources in another
Gateway API Architecture
The Gateway API follows a layered design with clear separation of concerns:
- GatewayClass: Defines a type of load balancing infrastructure, owned by infrastructure providers or cluster operators. It represents the underlying implementation (e.g., a specific load balancer type, service mesh, or ingress controller)
- Gateway: Represents a specific instance of the infrastructure, typically owned by platform or network administrators. It's a deployment of a particular GatewayClass with specific listeners
- Route resources: Define traffic routing rules, typically owned by application developers. These attach to Gateways and control traffic flow to backend services
- Policy attachments: Add cross-cutting functionality like rate limiting, authentication, or traffic metrics. These can attach to Gateways or Routes
This layered architecture enables clear ownership boundaries and simplifies multi-team collaboration on network configuration.
Basic Gateway Example
This Gateway example defines:
- Two listeners - one for HTTP (port 80) and one for HTTPS (port 443)
- Namespace controls that determine which Routes can attach to each listener
- TLS configuration for the HTTPS listener referencing a certificate
- Implementation details via the gatewayClassName reference
The Gateway object is typically managed by platform or networking teams, with application teams creating Routes that attach to it.
HTTPRoute Configuration
Basic HTTP Routing
This basic HTTPRoute:
- Attaches to the
prod-web-gateway
in theprod
namespace - Handles requests for the hostname "store.example.com"
- Routes requests with path prefix
/catalog
to thecatalog-svc
service - Routes requests with path prefix
/cart
to thecart-svc
service
Advanced HTTP Routing
This advanced HTTPRoute demonstrates:
- Combining path and header matching for more specific routing
- Traffic splitting across multiple backend services using weights
- Canary deployment pattern with 90/10 traffic distribution
- Sophisticated request matching that considers both path and headers
These capabilities allow for advanced deployment patterns like A/B testing, canary releases, and gradual migrations between service versions.
Cross-Namespace Routing
For security reasons, cross-namespace references require explicit authorization using ReferenceGrant. This security feature prevents unauthorized access to services across namespace boundaries:
ReferenceGrant provides a precise security model for cross-namespace routing:
- It's defined in the target namespace (where the referenced resources exist)
- It explicitly lists which resources from which namespaces can make references
- It specifies which kinds of resources can be referenced
- Without a ReferenceGrant, cross-namespace references are rejected by controllers
This model follows the principle of least privilege, requiring explicit opt-in for cross-namespace references rather than allowing them by default, enhancing the security posture of multi-tenant clusters.
TLS Configuration
This TLS configuration demonstrates:
- TLS Termination: The Gateway terminates TLS connections (decrypts traffic)
- Certificate References: References a Kubernetes Secret containing TLS certificate and private key
- Namespace Permissions: Allows Routes from all namespaces to attach to this listener
The Gateway API supports multiple TLS modes:
- Terminate: The Gateway handles TLS termination (decryption)
- Passthrough: Encrypted traffic is passed through to backend services (for end-to-end encryption)
For production systems, you might also configure:
- Multiple certificates for different domains
- Certificate rotation strategies
- Automatic certificate management with cert-manager
- TLS version and cipher suite restrictions
Traffic Splitting and Weighted Routing
Canary Deployments
This canary deployment pattern enables:
- Gradual rollout: New versions can be tested with a small percentage of traffic
- Risk mitigation: Limits the impact of potential issues in the new version
- Progressive delivery: Weights can be adjusted over time to increase traffic to the new version
- Performance comparison: Traffic to both versions allows performance comparison
- Quick rollback: Simply adjust weights to 100/0 to roll back if issues are detected
Header-Based Routing
Header-based routing enables sophisticated traffic management:
- Device-specific routing: Different backends for mobile vs. desktop users
- Feature targeting: Route users with specific headers to feature-specific implementations
- Testing with specific users: Target internal users with custom headers
- API versioning: Route based on API version headers
- Geographic routing: Route based on geolocation headers from edge proxies
You can combine header matching with path matching and weights for even more sophisticated routing scenarios.
TCPRoute and GRPCRoute
Gateway API supports multiple protocol-specific route types, providing native handling for different protocols beyond HTTP:
The Gateway API provides protocol-aware routing:
- TCPRoute:
- Simple TCP forwarding without HTTP-specific features
- Useful for databases, messaging systems, and custom protocols
- Limited matching capabilities (no path/header matching)
- Can route to different backends based on listener or port
- GRPCRoute:
- Protocol-aware routing for gRPC services
- Match on gRPC service and method names
- Support for header matching and traffic splitting
- Better visibility and control for gRPC microservices
- Other route types:
- TLSRoute: For TLS passthrough scenarios
- UDPRoute: For UDP protocols (alpha)
This protocol diversity enables unified management of network traffic beyond what was possible with Ingress, making Gateway API suitable for a wider range of application networking scenarios.
Integration with Service Mesh
Istio Integration
- Istio implements Gateway API: Istio fully supports Gateway API as a first-class API
- Consistent routing model: Unified approach for north-south (ingress) and east-west (service-to-service) traffic
- Mesh-wide traffic policies: Apply consistent policies across both Gateway and mesh traffic
- Enhanced telemetry: Detailed observability for all traffic through Gateways
- Advanced security features: mTLS, authorization policies, and certificate management
Example Istio Gateway API implementation:
Linkerd Integration
- Gateway API compatibility: Linkerd works with Gateway API for ingress traffic
- Simplified service mesh model: Lightweight proxy focusing on core functionality
- Automatic mTLS: Transparent mutual TLS for secure communication
- Traffic metrics: Rich observability with Prometheus integration
- Lightweight implementation: Lower resource footprint than other mesh solutions
Example Linkerd and Gateway API:
Service meshes enhance Gateway API implementations by providing:
- End-to-end encryption with mTLS
- Detailed metrics and tracing
- Consistent policy enforcement
- Advanced traffic management capabilities
- Circuit breaking and resilience features
Policy Attachment
Policy attachment is a powerful extension mechanism in the Gateway API that allows for modular, reusable policies to be applied to routes and gateways. This approach:
- Separates concerns: Traffic routing logic remains separate from cross-cutting policies
- Enables reuse: The same policy can be applied to multiple routes
- Promotes standardization: Common policies can be templated and consistently applied
- Supports role separation: Security teams can manage policies while app teams manage routes
Other policy types include:
The policy attachment model is still evolving, with different implementations supporting various policy types. Check your specific Gateway implementation for supported policies.
Multi-Cluster Gateway Support
The Gateway API is designed to support multi-cluster scenarios through various approaches:
- Federation of Gateway resources: Centralized management of Gateway resources across multiple clusters
- Mirroring Gateway configurations: Replicating identical Gateway configurations across clusters
- Manual or automated replication of Gateway and Route resources
- Consistent naming and structure across environments
- Configuration management tools (Argo CD, Flux) to maintain consistency
- Service export/import models: Explicitly sharing services between clusters
- Multi-cluster service discovery: Discovering and accessing services across cluster boundaries
- DNS-based approaches (e.g., CoreDNS with multicluster plugin)
- Service mesh implementations (Istio, Linkerd multi-cluster)
- Custom multi-cluster service registries
- Cross-cluster load balancing: Distributing traffic across services in multiple clusters
- Global load balancers that direct traffic to regional/zonal clusters
- Health-aware routing between clusters
- Proximity-based routing to reduce latency
Multi-cluster Gateway setups require additional components and configurations beyond standard Gateway API resources. Major implementers like Istio, Cilium, and cloud providers offer various approaches to multi-cluster networking that build on Gateway API foundations.
Comparison with Ingress
Limitations of Ingress
- Limited protocol support: Primarily designed for HTTP/HTTPS only
- Basic routing capabilities: Simple path-based routing with limited matching options
- Annotation-based extensions: Non-standard extensions via implementation-specific annotations
- Implementation inconsistencies: Behavior varies significantly between different controllers
- Limited role separation: No clear boundaries between infrastructure, network, and application teams
Gateway API Advantages
- Protocol diversity: Native support for HTTP, HTTPS, TCP, TLS, gRPC, and UDP
- Advanced traffic routing: Sophisticated matching and traffic splitting capabilities
- Standardized extensions: Well-defined extension points with policy attachment model
- Consistent implementations: More standardized behavior across different controllers
- Clear separation of responsibilities: Role-oriented API design with explicit boundaries
- Improved multi-team workflows: Delegation of specific networking responsibilities
Implementation Status
The Gateway API has different maturity levels:
- Core resources (Gateway, HTTPRoute): Beta status in v1.2+ - suitable for production use
- TLSRoute, TCPRoute: Alpha status - stable API but may change in future versions
- GRPCRoute, UDPRoute: Alpha status - API may change significantly
- Policy attachment: Alpha status - experimental feature with evolving API
Major implementations include:
- Contour: HashiCorp's L7 proxy with robust Gateway API support
- Istio: Full-featured service mesh with advanced Gateway API integration
- Kong: API gateway with Gateway API controller
- Traefik: Cloud-native edge router with Gateway API support
- Envoy Gateway: Official Envoy-based implementation
- Cilium: eBPF-based networking with Gateway API support
- AWS Gateway API Controller: Native AWS integration
- Google Kubernetes Engine (GKE): Native support in Google Cloud
- Azure Application Gateway: Native support in Azure
- Nginx Gateway Fabric: Official Nginx-based implementation
Each implementation has different levels of support for various Gateway API features, with some focusing on core HTTP routing and others supporting the full range of protocol-specific routes and policies.
Best Practices
Design Principles
- Use namespace isolation: Separate Gateways by environment, team, or security boundary
- Implement least privilege: Restrict Gateway access with explicit allowedRoutes
- Define clear ownership boundaries: Use labels and annotations to indicate resource ownership
- Structure routes logically: Organize routes by domain, application, or function
- Follow naming conventions: Use consistent naming patterns for all Gateway API resources
- Document routing policies: Add annotations to describe routing behavior and ownership
Operational Guidelines
Additional operational considerations:
- Implement health checks: Monitor Gateway health and backend service availability
- Set up alerting: Create alerts for Gateway errors, certificate expiration, and traffic anomalies
- Establish backup procedures: Backup Gateway configurations and have rollback procedures
- Create runbooks: Document common operations and troubleshooting procedures
- Version control: Store Gateway configurations in Git with proper review processes
- Automated testing: Test Gateway configurations before deployment
- Capacity planning: Monitor Gateway resource usage and plan for scaling
Troubleshooting
Common issues and troubleshooting approaches:
- Route not accepted: Check parentRefs and ReferenceGrants
- TLS issues: Verify certificate references and secrets
- Cross-namespace problems: Ensure proper ReferenceGrants exist
- Implementation differences: Check provider documentation
- Status reporting: Examine resource status fields
- Gateway not provisioned: Verify GatewayClass exists and is supported
When troubleshooting Gateway API issues, check both the status fields of the resources and the logs of the controller implementation. Most Gateway controllers add detailed information to the status fields of Gateway and Route resources that can help diagnose problems.
Gateway API Roadmap
Upcoming Features
- Enhanced policy attachment: More standardized policies for security, traffic management, and observability
- Layer 7 load balancing improvements: Advanced traffic management for HTTP and gRPC
- Extended service mesh integration: Deeper integration with service mesh implementations
- Multi-cluster gateway federation: Standardized approach to multi-cluster networking
- Advanced security features: Enhanced TLS configuration, certificate management, and authentication
- Implementation consistency: More aligned behavior across different Gateway API implementations
Evolution Strategy
- Stable core resources: Stabilize foundational resources before experimental features
- Extensible design: Well-defined extension points for vendor-specific capabilities
- Graduation of alpha features: Progressive maturation of experimental features based on feedback
- Community feedback incorporation: Active engagement with users and implementers
- Kubernetes SIG Network oversight: Governance through established Kubernetes processes
- Broad implementation support: Ensure multiple implementations for all features
The Gateway API is following Kubernetes' API evolution patterns, with careful attention to backwards compatibility and gradual feature maturation. The core resources are reaching stability while newer features continue to evolve based on real-world usage and feedback.
Resources
To learn more about Gateway API:
- Official Gateway API Documentation - Comprehensive documentation covering all aspects of the API
- Kubernetes SIG Network - The special interest group responsible for Gateway API development
- Gateway API GitHub Repository - Source code, issue tracking, and development discussions
- Gateway API Concept Documentation - Detailed explanations of key concepts and resource relationships
- Implementation Guides - Information about different Gateway API implementations
- Gateway API Slack Channel - Join #sig-network-gateway-api for community discussions
- Gateway API Presentations - Videos and slides explaining Gateway API concepts
- Gateway API Specification - Formal specification of the API
- Gateway API Guides - Practical guides for various Gateway API use cases
- Gateway API Conformance Tests - Tests to verify implementation conformance
Additional resources for specific implementations: