Amazon VPC Lattice Gateway API Controller

repository·main·Indexed 42 days ago

https://github.com/aws/aws-application-networking-k8s

A Kubernetes implementation of the Kubernetes Gateway API used to orchestrate AWS VPC Lattice resources. It maps Kubernetes objects like Gateway and HTTPRoute to AWS networking infrastructure and provides custom resources in the application-networking.k8s.aws/v1alpha1 API group, including AccessLogPolicy, IAMAuthPolicy, ServiceExport, ServiceImport, and ServiceNetwork.

Tokens
55.2K
Snippets
118
Records
200
Agent score
55%

What's inside Amazon VPC Lattice Gateway API Controller

  1. Overview of Amazon VPC Lattice Gateway API Controller

    main
    The Amazon VPC Lattice Gateway API Controller is a Kubernetes implementation of the Kubernetes Gateway API. It is designed to run within a Kubernetes cluster to orchestrate AWS VPC Lattice resources. It achieves this by mapping Kubernetes Custom Resource Definitions (CRDs), specifically Gateway and HTTPRoute, to the underlying AWS VPC Lattice infrastructure.
  2. What is the Amazon VPC Lattice Gateway API Controller?

    main

    The Amazon VPC Lattice Gateway API Controller is an implementation of the Kubernetes Gateway API. It allows you to manage Amazon VPC Lattice resources—such as VPC Lattice Services, service networks, and Target Groups—using standard Kubernetes APIs and Custom Resource Definitions (CRDs).

    When installed in a cluster, the controller watches for Gateway API resources (like Gateway and HTTPRoute) and automatically provisions the corresponding Amazon VPC Lattice objects. This provides a Kubernetes-native experience for managing network connectivity, service discovery, and security without requiring custom code or sidecar proxies.

  3. What is ServiceExport and how does it work?

    main

    A ServiceExport resource enables a Kubernetes Service for multi-cluster traffic setup within the AWS Gateway API Controller. When you create a ServiceExport, the controller internally creates a standalone VPC Lattice target group.

    Key behaviors:

    • Multi-cluster connectivity: Other clusters can import this exported service using a ServiceImport resource.
    • Standalone usage: You can use ServiceExport even without ServiceImport if you only need the VPC Lattice target groups created (e.g., for use in VPC Lattice setups outside of Kubernetes).
    • Implementation note: This is a custom implementation for Gateway API integration and is not the standard Kubernetes Multicluster Service APIs.

    Note: ServiceExport is not a direct implementation of the Kubernetes Multicluster Service APIs; instead, the AWS Gateway API Controller uses its own version of the resource for Gateway API integration.

  4. What is GRPCRoute?

    main
    The GRPCRoute is a custom resource defined in the Kubernetes Gateway API that specifies how gRPC traffic should be routed. It allows for routing rules based on match criteria such as service names and specific gRPC methods. This ensures gRPC traffic is directed to the correct backend services within a Kubernetes environment via VPC Lattice.
  5. What is a ServiceImport and how does it work?

    main

    A ServiceImport is a resource used to refer to a Service or VPC Lattice target group located outside the current cluster. It allows you to distribute traffic across multiple VPCs, multiple clusters, or between EKS-native backends and existing VPC Lattice target groups (such as those pointing to ECS, Lambda, EC2, or ALB).

    ServiceImport is used as a backendRef within Gateway API routes (HTTPRoute, GRPCRoute, or TLSRoute). It is not an implementation of the Kubernetes Multicluster Service APIs, but a custom resource used by the AWS Gateway API Controller for VPC Lattice integration.

    Key Constraints:

    • You cannot send traffic directly to a ServiceImport; it must be used as a backendRef in a route.
    • BackendRef ports are not respected; you must use the port annotation on the corresponding ServiceExport instead.
    • In Mode 3 (Direct ARN), the controller treats the target group as a reference only: it will not tag it with ManagedBy, will not register targets on it, and will not delete it.
  6. Integrate ServiceExport with TargetGroupPolicy

    main

    You can use a TargetGroupPolicy to configure protocol, protocol version, and health check settings for a ServiceExport. When a policy targets a ServiceExport, the configuration is automatically propagated to all target groups across all clusters participating in the multi-cluster service mesh.

    Protocol Overriding: If you use exportedPorts, the TargetGroupPolicy settings for protocol and protocolVersion will override the default protocol inferred from the routeType. For example, you can set routeType: HTTP in the ServiceExport but use protocol: HTTPS in the TargetGroupPolicy to enable secure communication between VPC Lattice and your backend pods.

    # ServiceExport with HTTP routeType
    apiVersion: application-networking.k8s.aws/v1alpha1
    kind: ServiceExport
    metadata:
      name: secure-service
    spec:
      exportedPorts:
      - port: 443
        routeType: HTTP  # Default would be HTTP/1
    ---
    # TargetGroupPolicy overriding to HTTPS
    apiVersion: application-networking.k8s.aws/v1alpha1
    kind: TargetGroupPolicy
    metadata:
      name: https-override
    spec:
      targetRef:
        group: "application-networking.k8s.aws"
        kind: ServiceExport
        name: secure-service
      protocol: HTTPS        # Overrides HTTP from routeType
      protocolVersion: HTTP2 # Overrides HTTP1 default
      healthCheck:
        enabled: true
        path: "/health"
        protocol: HTTPS
        protocolVersion: HTTP2
        statusMatch: "200-299"
  7. Manage ServiceNetwork deletion

    main

    The controller uses a finalizer to ensure that Lattice resources are properly cleaned up before the Kubernetes Custom Resource (CR) is removed.

    Deletion of a ServiceNetwork CR will be blocked if:

    1. A Gateway with the same name exists and is controlled by the Lattice gateway controller.
    2. The Lattice service network still has active associations (such as VPC, service, resource, or endpoint associations).

    If deletion is blocked due to active associations, the specific Lattice API error message will be surfaced in the CR status field.

  8. What are Pod readiness gates and when to use them

    main

    The AWS Gateway API controller supports Pod readiness gates to ensure a pod is registered to the VPC Lattice and healthy before it is considered 'Ready' by Kubernetes.

    This is critical for achieving zero-downtime rolling deployments, especially when:

    • You have a low number of replicas.
    • The rollout of new pods happens faster than the AWS Gateway API controller can register them and for their health state to turn Healthy in the VPC Lattice target group.

    By setting a readiness condition on the pods, the controller prevents a rolling update from terminating old pods until the new pods are confirmed Healthy in the VPC Lattice target group and ready to receive traffic. The condition status is set to True only when the corresponding target in the VPC Lattice target group shows a Healthy state.

  9. Handle cross-cluster routing with identical service names

    main

    If multiple clusters have services with the same name, use annotations to differentiate them in the federation.

    1. In Exporting Clusters: Use the application-networking.k8s.aws/service-name annotation on the ServiceExport to point to the actual Kubernetes Service name, while giving the ServiceExport a unique metadata.name.
    2. In Importing Clusters: Use the application-networking.k8s.aws/export-name annotation on the ServiceImport to reference the specific ServiceExport name from the remote cluster.
    # In cluster1 (Exporting)
    apiVersion: application-networking.k8s.aws/v1alpha1
    kind: ServiceExport
    metadata:
      name: checkout-cluster1
      annotations:
        application-networking.k8s.aws/federation: "amazon-vpc-lattice"
        application-networking.k8s.aws/service-name: "checkout"
    spec:
      exportedPorts:
      - port: 80
        routeType: HTTP
    ---
    # In cluster2 (Importing)
    apiVersion: application-networking.k8s.aws/v1alpha1
    kind: ServiceImport
    metadata:
      name: checkout-import-1
      annotations:
        application-networking.k8s.aws/export-name: "checkout-cluster1"
        application-networking.k8s.aws/aws-eks-cluster-name: "cluster1"
    spec:
      type: ClusterSetIP
      ports:
      - port: 80
        protocol: TCP
  10. Key capabilities of the Amazon VPC Lattice Gateway API Controller

    main

    The controller enables several networking and security patterns across VPCs and accounts:

    • Seamless Connectivity: Handle network connectivity between services spanning different VPCs and AWS accounts.
    • Multi-cluster Service Discovery: Discover VPC Lattice services that span multiple Kubernetes clusters.
    • Defense-in-depth Security: Implement security strategies to protect communication between services.
    • Traffic Observability: Observe request/response traffic across services.
    • Consistent Health Checks: Ensure consistent health check configurations across multi-cluster deployments via automatic policy propagation.
    • Cross-platform Publishing: Publish services running on Kubernetes clusters to other AWS compute platforms like AWS Lambda or Amazon EC2.
  11. Understand Kubernetes Service features and limitations

    main

    A Kubernetes Service defines a logical set of Pods (a microservice) and the policy used to access them. The target Pods are identified via a selector.

    Key Features

    • Load Balancing: Distributes network traffic across the targeted Pods.
    • Service Types: Supports ClusterIP (default), NodePort, and LoadBalancer.
    • Stable IP Address: Provides a consistent IP address even as the underlying Pods are replaced.

    Limitations

    • Immutable Fields: The selector and type fields cannot be updated after the Service is created.
    • Namespace Boundary: Services can only route to Pods located within the same namespace.
    • Unsupported Types: The ExternalName service type is not supported by this controller.
  12. Use HTTPRoute to manage HTTP/HTTPS traffic routing

    main

    The HTTPRoute resource allows you to define and manage the routing of HTTP and HTTPS traffic within your Kubernetes cluster using the AWS Gateway API Controller. It enables traffic to be directed to backends based on path matching, HTTP methods, and header matching.

    Key Features

    • Routing Traffic: Forwards HTTP traffic to servers within your cluster.
    • Path Matching: Supports exact paths or paths with a specified prefix.
    • Method Matching: Supports matching based on specific HTTP Methods.
    • Header Matching: Enables matching based on specific headers in the HTTP request.

    Limitations

    • Listener Protocol: The sectionName in parentRefs must refer to an http or https listener in the parent Gateway.
    • Method Matches: Only one method match is allowed per rule.
    • QueryParam Matches: Query parameter matching is not supported.
    • Header Matches Limit: A maximum of 5 header matches per rule is supported.
    • Case Insensitivity: All path matches are case-insensitive.