About gateway distribution

With Gloo Gateway, you can create API gateways for ingress, egress, waypoint, and other types of traffic management across your clusters. Keeping these gateways in sync across your clusters can be challenging.

Normally, you create many routing resources such as Gateways, HTTPRoutes, and Upstreams in each cluster. You might use a CI/CD integration such as ArgoCD to keep these resources in sync. However, this approach requires an external integration that might not fit into your existing workflows.

By using Gloo Gateway with a multicluster relay setup that is provided by Gloo Mesh Enterprise, you get the ability to distribute gateway configuration across clusters. This way, you can federate your gateway configuration across your clusters without the need for an external integration.

The relay connection consists of a Gloo Mesh management server in a source cluster and a Gloo Mesh agent in each workload cluster. This way, the management server can send configuration in the source cluster to each of the connected workload clusters. This configuration includes both Kubernetes Gateway API and Gloo Gateway resources, such as Gateways, HTTPRoutes, and Upstreams. The workload clusters have Gloo Gateway installed so that the distributed resources provide the API gateway functionality per cluster.

For example, a distributed Gateway triggers Gloo Gateway to create a gateway proxy for the workload cluster. Then, distributed HTTPRoutes can attach to the distributed Gateway and forward traffic to distributed Upstreams and further to the apps that run in the workload clusters.

How gateway distribution works

Gateway distribution works by using annotations. Review the following diagrams and learn how you can use the annotation to distribute resources in your environment.

Distributable resources

You can distribute the following gateway resources:

  • Gateways

  • GatewayClass

  • GatewayParameters

  • HTTPRoutes

  • HTTPListenerOptions

  • ListenerOptions

  • RouteOptions

  • VirtualHostOptions

  • Upstreams

Distributed resource FAQs

Review the following frequently asked questions to guide your usage of the config distribution feature.

What is the name of distributed resources?

When the resource is distributed, the name of the resource is the same as the original resource.

In the workload clusters, the copied resources also get a special annotation, gloo.solo.io/distributed-source. The naming convention for the annotation is as follows:

  gloo://<cluster>/ns/<namespace>/kind/<kind>/name/<name>
  

This way, you can tell which resource controls the distributed copy. You can use this information to help debugging or automate tracing tools.

  apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  annotations:
    gloo.solo.io/distributed-source: "gloo://management-cluster/ns/default/kind/Gateway/name/my-gateway"
...
  

What namespace is the distributed resource created in?

The namespace is the same as the original resource by default, unless otherwise specified in the source annotation.

Can I make changes to my distributed resources?

Yes, but only by changing the source resource in the management cluster.

Any changes made to the resource in the workload cluster are not reflected in the management cluster. Furthermore, the changes are automatically overwritten upon the next relay sync.

What happens if I delete the source resource?

If you delete the source resource, the distributed resource is also deleted.

How should I set up my distributed resources?

Review How it works to plan how to distribute your resources via annotations across clusters and namespaces.

Keep in mind that the config distribution does not check for resource consistency across clusters. For example, you might have a Gateway, HTTPRoute, Upstream, and several policies in the source cluster. If you annotate only the Gateway and policies, the HTTPRoute and Upstream are not distributed to the workload clusters. If you do not have existing HTTPRoutes and Upstreams already in the workload clusters, the routing does not work. Make sure that you distribute all the resources that you need for your routing use case.

Also, be aware of potential conflicts in your workload clusters in more advanced scenarios, such as policy inheritance or route delegation. For example, if you distribute a policy from the management cluster but have a pre-existing policy in the workload cluster, this might cause a conflict.

Before you begin

  1. Create multiple clusters for your distributed gateway scenario.

    • Management cluster: One cluster must be the management cluster where you create the resources that you want to distribute to your workload clusters. You install the Gloo Mesh management plane into this cluster. You can choose whether to run this cluster as a workload cluster as well, in which case you also install Gloo Gateway so that gateway proxies can be created from your Gateway resources.
    • Workload clusters: Other clusters are remote workload clusters that are registered with the management cluster so that they can receive the distributed resources. You run the Gloo Mesh agents and Gloo Gateway in these clusters.
  2. Set environment variables for your management and workload clusters.

      export MGMT_CLUSTER=<management-cluster>
    export MGMT_CONTEXT=<management-cluster-context>
    export REMOTE_CLUSTER=<workload-cluster>
    export REMOTE_CONTEXT=<workload-cluster-context>
      
  3. Set an environment variable for the Gloo Mesh Enterprise installation. Gateway distribution is supported in version 2.8.0 and later.

      export GLOO_MESH_VERSION=2.8.0
      
  4. Save either your Gloo Gateway Enterprise or Gloo Mesh Enterprise license in an environment variable. An Enterprise-level license is required to use the config distribution feature.

    • Gloo Gateway:

        export GLOO_GATEWAY_LICENSE_KEY=<gateway-license>
        
    • Gloo Mesh Enterprise:

        export GLOO_MESH_LICENSE_KEY=<mesh-license>
        
  5. In the workload clusters, create the sample httpbin app.

Step 1: Set up the management cluster

Set up the management cluster with the relay management server and Kubernetes Gateway resources.

  1. Install the Gloo Mesh management server in your management cluster with the ConfigDistribution feature gate enabled. The following tabs include a basic example.

  2. Install the Kubernetes Gateway API CRDs. This way, you can create Kubernetes Gateway resources in your management cluster, including Gateways. Later, these resources are distributed to your remote cluster.

      kubectl apply --context $MGMT_CONTEXT -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.1/standard-install.yaml
      
  3. Choose whether to install Gloo Gateway in the management cluster.

Step 2: Set up the workload cluster

Install Gloo Gateway in your workload cluster so that you can automatically create gateway proxies from distributed Gateway resources. Register the workload cluster with the Gloo management server to establish a relay connection with the management cluster.

  1. Install the Kubernetes Gateway API CRDs.

      kubectl apply --context $REMOTE_CONTEXT -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.1/standard-install.yaml
      
  2. Install Gloo Gateway Enterprise.

  3. If you have not already done so, install the Gloo Mesh agent in your workload cluster and register it with the management cluster.

  4. Verify the relay connection between the management and workload clusters. The management server and agent must be connected so that resources can be successfully distributed from the management cluster to the workload cluster.

      meshctl check --kubecontext $MGMT_CONTEXT
      

    Example output:

      🟢 Mgmt server connectivity to workload agents
    
    Cluster         | Registered | Connected Pod                                                                    
    $REMOTE_CLUSTER | true       | gloo-mesh/gloo-mesh-mgmt-server-76845d886d-fnpsp
    
    Connected Pod                                    | Clusters    
    gloo-mesh/gloo-mesh-mgmt-server-76845d886d-fnpsp | 1  
      
  5. Optional: Repeat these steps for each workload cluster that you want to distribute gateway resources to.

Step 3: Distribute gateway configuration

Create the gateway configuration that you want to distribute across clusters in the management cluster. The configuration includes the Gateway itself along with the routing resources that the gateway serves traffic for, such as HTTPRoutes and Upstreams.

  1. Create a Gateway.

      kubectl apply --context $MGMT_CONTEXT -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: distributed-gateway
      namespace: gloo-mesh
      labels:
        example: config-distro
      annotations:
        gloo.solo.io/distribute-to: "*/gloo-system"
    spec:
      gatewayClassName: gloo-gateway-distribute
      listeners:
      - protocol: HTTP
        port: 8080
        hostname: mydomain.com
        name: http
        allowedRoutes:
          namespaces:
            from: All
    EOF
      
    SettingDescription
    namespaceThe namespace where the Gateway is created. Because the management cluster does not have Gloo Gateway installed, the Gateway is created in the gloo-mesh namespace.
    gloo.solo.io/distribute-to: "*/gloo-system"The annotation that tells the Gloo management server to copy the resource configuration to the selected clusters and namespaces. The wildcard (*) selects all connected clusters for config distribution. You can also specify multiple clusters, such as "qa, canary", or select no clusters by leaving the value blank (""). Cluster names must match the name in the KubernetesCluster for the registered cluster. The configuration is distributed to the gloo-system namespace in the workload clusters, which differs from the namespace that this Gateway is created in the source cluster.
    gatewayClassName: gloo-gateway-distributeThe GatewayClass that Gloo uses for distributing configuration. This way, Gloo Gateway does not create a gateway proxy in the management cluster where this Gateway resource is created. Instead, the Gateway configuration is copied to the workload clusters and the GatewayClass field is updated to refer to the gloo-gateway GatewayClass. Then, Gloo Gateway automatically creates the gateway proxies in each workload cluster. If you want the gateway proxy to be created in both the management and remote clusters, you can use the regular gloo-gateway GatewayClass value.
    listenersThe listener configuration for the Gateway. The example sets up an HTTP listener on mydomain.com, but you can update to use your own.
  2. Create an Upstream to represent the backend service that you want to route traffic to. The following example uses the httpbin service. You don’t need httpbin in your management cluster. Instead, this app runs in the workload cluster that the gateway configuration is distributed to. Note that the Upstream includes the gloo.solo.io/distribute-to annotation, which configures the namespace to the httpbin namespace in the workload cluster where the app runs.

      kubectl apply --context $MGMT_CONTEXT -f- <<EOF
    apiVersion: gloo.solo.io/v1
    kind: Upstream
    metadata:
      name: httpbin
      namespace: gloo-mesh
      labels:
        example: config-distro
      annotations:
        gloo.solo.io/distribute-to: "*/httpbin"
    spec:
      kube:
        serviceName: httpbin
        serviceNamespace: httpbin
        servicePort: 8000
    EOF
      
  3. Create an HTTPRoute that refers to the Gateway and Upstream that you previously created. Just like the Upstream, the HTTPRoute includes the gloo.solo.io/distribute-to annotation.

      kubectl apply --context $MGMT_CONTEXT -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: httpbin-mydomain
      namespace: gloo-mesh
      labels:
        example: config-distro
      annotations:
        gloo.solo.io/distribute-to: "*/httpbin"
    spec:
      parentRefs:
        - name: distributed-gateway
          namespace: gloo-mesh
      rules:
        - backendRefs:
          - name: httpbin
            kind: Upstream
            group: gloo.solo.io
    EOF
      

Good job! You created gateway configuration that is automatically distributed to the workload clusters.

Step 4: Verify the distributed gateway resources

In your workload cluster, verify that the configuration is distributed. The resources have the same name as the source and include a special annotation.

  1. List the distributed resources in the workload cluster.

      kubectl get httproutes,upstreams,gateways --context $REMOTE_CONTEXT -A -l example=config-distro
      

    Example output:

      NAME                                                                                 HOSTNAMES   AGE
    httproute.gateway.networking.k8s.io/httpbin-mydomain-gateway-distro-distributed-gateway               11d
    
    NAME                                                          AGE
    upstream.gloo.solo.io/httpbin-gateway-distro-distributed-gateway   11d
    
    NAME                                                    CLASS          ADDRESS          PROGRAMMED   AGE
    gateway.gateway.networking.k8s.io/distributed-gateway   gloo-gateway   34.162.244.194   True         11d   
      
  2. Describe one of the distributed resources to confirm that it follows the naming convention. Names are subject to Kubernetes naming conventions, such as the 63-character limit.

    The following naming conventions apply:

    • Resource name: The same as the source resource name.
    • gloo.solo.io/distributed-source annotation: A special annotation that includes the source of the distributed resource, in the format gloo://<cluster>/ns/<namespace>/kind/<kind>/name/<name>.
      kubectl describe httproute httpbin-mydomain-gateway-distro-distributed-gateway -n gateway-distro --context $REMOTE_CONTEXT
      

    Example output:

      Name:         httpbin-mydomain
    Namespace:    httpbin
    Labels:       agent.gloo.solo.io=gloo-mesh
                  cluster.multicluster.solo.io=gloo-gateway-docs-mgt
                  example=config-distro
                  owner.gloo.solo.io/name=gloo-mesh
                  reconciler.mesh.gloo.solo.io/name=gloo-gateway
                  relay.solo.io/cluster=gloo-gateway-docs-mgt
    Annotations:  gloo.solo.io/distributed-source: gloo://$MGMT_CLUSTER/ns/gloo-mesh/kind/HTTPRoute/name/httpbin-mydomain
    API Version:  gateway.networking.k8s.io/v1
    Kind:         HTTPRoute
    ...
      

Nice! You confirmed that your distributed resources are in the remote cluster.

Step 5: Verify routing behavior

Now that you have distributed gateway configuration, you can verify that the routes work as expected.

  1. Get the external address of the distributed gateway and save it in an environment variable.

  2. Send a request to the httpbin app through the distributed gateway.

      curl -vik http://$INGRESS_GW_ADDRESS:8080/status/200 -H "host: mydomain.com:8080"
      

    Example output:

      HTTP/1.1 200 OK
      

Next steps

Whenever you want to update the config, you can edit the source config in the management cluster. The change is automatically distributed to the workload clusters. Don’t worry if you make any changes to the distributed config in the workload clusters. These changes are quickly overwritten back so that your distributed config does not drift from the source config.

For ideas of how to set up your gateways, see Deployment patterns.

Cleanup

You can optionally remove the resources that you set up as part of this guide.
  1. Delete the gateway config resources in the management cluster.

      kubectl delete httproute,upstream,gateway --context $MGMT_CONTEXT -A -l example=config-distro
      
  2. Verify that the resources are deleted in the workload clusters.

      kubectl get httproute,upstream,gateway --context $REMOTE_CONTEXT -A -l example=config-distro
      
  3. Optionally disable the config distribution feature gate in your Gloo Mesh Enterprise installation in the management cluster.

    1. In the mgmt-plane.yaml file, set the featureGates.ConfigDistribution to false.

        ...
      featureGates:
        ConfigDistribution: false
        
    2. Upgrade your Helm installation.

        helm upgrade -i gloo-platform gloo-platform/gloo-platform \
       --kube-context $MGMT_CONTEXT \
       -n gloo-mesh \
       --version $GLOO_MESH_VERSION \
       --values mgmt-plane.yaml \
       --set common.cluster=$MGMT_CLUSTER \
       --set licensing.glooMeshCoreLicenseKey=$GLOO_MESH_LICENSE_KEY
        
  4. Optionally uninstall Gloo Mesh Enterprise.