Chapter 20. Exposing services on the application network using YAML
After creating an application network by linking sites, you can expose services from one site using connectors and consume those services on other sites using listeners. A routing key is a string that matches one or more connectors with one or more listeners. For example, if you create a connector with the routing key backend, you need to create a listener with the routing key backend to consume that service.
This section assumes you have created and linked at least two sites.
20.1. Creating a connector using YAML Copy linkLink copied to clipboard!
A connector binds a local workload to listeners in remote sites. Listeners and connectors are matched using routing keys.
For more information about connectors see Connector concept
Procedure
Create a workload that you want to expose on the network, for example:
kubectl create deployment backend --image quay.io/skupper/hello-world-backend --replicas 3
kubectl create deployment backend --image quay.io/skupper/hello-world-backend --replicas 3Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a connector resource YAML file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This creates a connector in the
eastsite and exposes thebackenddeployment on the network on port 8080. You can create a listener on a different site using the matching routing keybackendto address this service.To create the connector resource:
kubectl apply -f <filename>
kubectl apply -f <filename>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<filename>is the name of a YAML file that is saved on your local filesystem.Check the connector status:
kubectl get connector
kubectl get connectorCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
NAME STATUS ROUTING-KEY SELECTOR HOST PORT HAS MATCHING LISTENER MESSAGE backend Pending backend app=backend 8080 false No matching listeners
NAME STATUS ROUTING-KEY SELECTOR HOST PORT HAS MATCHING LISTENER MESSAGE backend Pending backend app=backend 8080 false No matching listenersCopy to Clipboard Copied! Toggle word wrap Toggle overflow 📌 NOTE By default, the routing key name is set to the name of the connector. If you want to use a custom routing key, set the
--routing-keyto your custom name.
There are many options to consider when creating connectors using YAML, see CLI Reference, including frequently used options.
20.2. Creating a listener using YAML Copy linkLink copied to clipboard!
A listener binds a local connection endpoint to connectors in remote sites. Listeners and connectors are matched using routing keys.
Procedure
- Identify a connector that you want to use. Note the routing key of that connector.
Create a listener resource YAML file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This creates a listener in the
westsite and matches with the connector that uses the routing keybackend. It also creates a service namedeast-backendexposed on port 8080 in the current namespace.To create the connector resource:
kubectl apply -f <filename>
kubectl apply -f <filename>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where
<filename>is the name of a YAML file that is saved on your local filesystem.Check the listener status:
kubectl get listener
kubectl get listenerCopy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
NAME ROUTING KEY PORT HOST STATUS HAS MATCHING CONNECTOR MESSAGE backend backend 8080 east-backend Ready true OK
NAME ROUTING KEY PORT HOST STATUS HAS MATCHING CONNECTOR MESSAGE backend backend 8080 east-backend Ready true OKCopy to Clipboard Copied! Toggle word wrap Toggle overflow 📌 NOTE There must be a
MATCHING-CONNECTORfor the service to operate.
There are many options to consider when creating connectors using YAML, see CLI Reference, including frequently used options.