Connect Services to the Edge
  • 11 Apr 2024
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

Connect Services to the Edge

  • Dark
    Light
  • PDF

Article summary

The networking entry point for a greymatter tenant project is called an edge node or application edge node. The greymatter init command templates out manifests and configurations for the edge node; however, you may need to make changes.

This guide will walk you through connecting a service to an application edge node.

Prerequisites

  • A greymatter 1.8.x instance

  • A tenant project with at least one service

Add the edge Block

The GSL #Service definition contains an edge object that configures the connection between the service and an edge. Embedding this route configuration in the #Service definition allows for tight coupling of configurations. But, this method only allows for a service to connect with one edge and only using HTTP.

You can route raw TCP streams through an edge to a service, but it requires opening a new TCP listener on the edge. See the guide on adding ingresses to learn how to do this.

Open the GSL service file for the service you want to connect to an edge.

Add an edge field inside the #Service definition, like so:

gsl.#Service & {
// omitted for brevity
	edge: {

	}
}

Inside the edge object, add these two fields:

edge: {
	edge_name: "<the edge name found in the GSL edge file>"
	routes: "<route path>": {}
}

Optionally, you can add a edge_ingress field set to the specific edge listener you want to handle this route.

The routes map should look familiar since it matches the schema of an #HTTPListener's routes field. The map keys are route paths that get matched against incoming requests and the values are configurations to execute upon a successful route match.

Once you defined the route path to match and any extra route configuration, link the route to the service with an upstream:

routes: "<route path>": {
	upstreams: (name): {
		gsl.#Upstream
		namespace: context.globals.namespace
	}
}

Inside the upstream block, you can configure the connection options between the edge and the service, for instance, to enable SPIRE or special load balancing.

The (name) syntax is how CUE allows for variable substitution inside areas where the use of a variable is ambiguous, like in key names. We want an upstream named the value of name not the literal value "name".


Was this article helpful?