Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 8. Specifying link cost
When linking sites, you can assign a cost to each link to influence the traffic flow. By default, link cost is set to 1
for a new link. In a service network, the routing algorithm attempts to use the path with the lowest total cost from client to target server.
If you have services distributed across different sites, you might want a client to favor a particular target or link. In this case, you can specify a cost of greater than
1
on the alternative links to reduce the usage of those links.NoteThe distribution of open connections is statistical, that is, not a round robin system.
- If a connection only traverses one link, then the path cost is equal to the link cost. If the connection traverses more than one link, the path cost is the sum of all the links involved in the path.
Cost acts as a threshold for using a path from client to server in the network. When there is only one path, traffic flows on that path regardless of cost.
NoteIf you start with two targets for a service, and one of the targets is no longer available, traffic flows on the remaining path regardless of cost.
- When there are a number of paths from a client to server instances or a service, traffic flows on the lowest cost path until the number of connections exceeds the cost of an alternative path. After this threshold of open connections is reached, new connections are spread across the alternative path and the lowest cost path.
Prerequisite
- You have set your Kubernetes context to a site that you want to link from.
- A token for the site that you want to link to.
Procedure
Create a link to the service network:
$ skupper link create <filename> --cost <integer-cost>
where
<integer-cost>
is an integer greater than 1 and traffic favors lower cost links.NoteIf a service can be called without traversing a link, that service is considered local, with an implicit cost of
0
.For example, create a link with cost set to
2
using a token file namedtoken.yaml
:$ skupper link create token.yaml --cost 2
Check the link cost:
$ skupper link status link1 --verbose
The output is similar to the following:
Cost: 2 Created: 2022-11-17 15:02:01 +0000 GMT Name: link1 Namespace: default Site: default-0d99d031-cee2-4cc6-a761-697fe0f76275 Status: Connected
Observe traffic using the console.
If you have a console on a site, log in and navigate to the processes for each server. You can view the traffic levels corresponding to each client.
NoteIf there are multiple clients on different sites, filter the view to each client to determine the effect of cost on traffic. For example, in a two site network linked with a high cost with servers and clients on both sites, you can see that a client is served by the local servers while a local server is available.
8.1. Exposing services on the service network from a Linux host
After creating a service network, exposed services can communicate across that network.
The general flow for working with services is the same for Kubernetes and Podman sites.
The skupper
CLI has two options for exposing services that already exist on a host:
-
expose
supports simple use cases, for example, a host with a single service. See Section 8.1.1, “Exposing simple services on the service network” for instructions. -
service create
andservice bind
is a more flexible method of exposing services, for example, if you have multiple services for a host. See Section 8.1.2, “Exposing complex services on the service network” for instructions.
8.1.1. Exposing simple services on the service network
This section describes how services can be enabled for a service network for simple use cases.
Prerequisites
- A Skupper Podman site
Procedure
Run a server, for example:
$ podman run --name backend-target --network skupper --detach --rm -p 8080:8080 quay.io/skupper/hello-world-backend
This step is not Skupper-specific, that is, this process is unchanged from standard processes for your host.
Create a service that can communicate on the service network:
$ skupper expose [host <hostname|ip>]
where
-
<host>
is the name of the host where the server is running. For example, the name of the container if you run the server as a container. -
<ip>
is the IP address where the server is running
For the example deployment in step 1, you create a service using the following command:
$ skupper expose host backend-target --address backend --port 8080
Options for this command include:
-
--port <port-number>
:: Specify the port number that this service is available on the service network. NOTE: You can specify more than one port by repeating this option. -
--target-port <port-number>
:: Specify the port number of pods that you want to expose. -
--protocol <protocol>
allows you specify the protocol you want to use,tcp
,http
orhttp2
-
Create the service on another site in the service network:
$ skupper service create backend 8080
8.1.2. Exposing complex services on the service network
This section describes how services can be enabled for a service network for more complex use cases.
Prerequisites
- A Skupper Podman site
Procedure
Run a server, for example:
$ podman run --name backend-target --network skupper --detach --rm -p 8080:8080 quay.io/skupper/hello-world-backend
This step is not Skupper-specific, that is, this process is unchanged from standard processes for your host.
Create a service that can communicate on the service network:
$ skupper service create <name> <port>
where
-
<name>
is the name of the service you want to create -
<port>
is the port the service uses
For the example deployment in step 1, you create a service using the following command:
$ skupper service create hello-world-backend 8080
-
Bind the service to a cluster service:
$ skupper service bind <service-name> <target-type> <target-name>
where
-
<service-name>
is the name of the service on the service network -
<target-type>
is the object you want to expose,host
is the only current valid value. -
<target-name>
is the name of the cluster service
For the example deployment in step 1, you bind the service using the following command:
$ skupper service bind hello-world-backend host hello-world-backend
-
8.1.3. Consuming simple services from the service network
Services exposed on Podman sites are not automatically available to other sites. This is the equivalent to Kubernetes sites created using skupper init --enable-service-sync false
.
Prerequisites
- A remote site where a service is exposed on the service network
- A Podman site
Procedure
- Log into the host as the user associated with the Skupper site.
Create the local service:
$ skupper service create <service-name> <port number>
8.2. Deleting a Podman site
When you no longer want the Linux host to be part of the service network, you can delete the site.
This procedure removes all containers, volumes and networks labeled application=skupper
.
To check the labels associated with running containers:
$ podman ps -a --format "{{.ID}} {{.Image}} {{.Labels}}"
Procedure
Make sure you are logged in as the user that created the site:
$ skupper status Skupper is enabled for "<username>" with site name "<machine-name>-<username>".
Delete the site and all podman resources (containers, volumes and networks) labeled with "application=skupper":
$ skupper delete Skupper is now removed for user "<username>".