Skip to content

Commit 8898e63

Browse files
authored
Update mkl (#294)
* mkl and link cost updates
1 parent cd96577 commit 8898e63

11 files changed

Lines changed: 362 additions & 85 deletions

File tree

input/kube-cli/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ The Skupper CLI is designed to generate and consume standard resources, ensuring
88

99
* [Create sites][site-configuration]
1010
* [Link sites][site-linking] (requires that one site has link access enabled)
11+
* [Configure link cost][link-cost]
1112
* [Expose and consume services][service-exposure]
1213

1314
[site-configuration]: ./site-configuration.html
1415
[site-linking]: ./site-linking.html
16+
[link-cost]: ./site-linking.html#kube-link-cost-cli
1517
[service-exposure]: ./service-exposure.html

input/kube-cli/site-linking.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,97 @@ All inter-site traffic is protected by mutual TLS and routed through the HTTP CO
252252
You can now expose services on the application network.
253253

254254
There are many options to consider when linking sites using the CLI, see [CLI Reference][cli-ref], including *frequently used* options.
255+
256+
<a id="kube-link-cost-cli"></a>
257+
## Specifying link cost
258+
<!--PROCEDURE-->
259+
260+
Link cost is a configurable integer value that influences how Skupper routes
261+
traffic across links between sites.
262+
The routing algorithm favors paths with the lowest total cost from client to
263+
target server.
264+
265+
**📌 NOTE**
266+
For most load-balancing and failover use cases, a [multi-key listener][mkl]
267+
provides per-service control.
268+
Link cost applies to **all services** that traverse a link; it is not
269+
possible to set different costs for distinct services on the same link.
270+
271+
Understanding link cost behavior:
272+
273+
* The default link cost is `1`. Local workloads have an implicit cost of `0`.
274+
* If a connection traverses more than one link, the path cost is the sum of
275+
all link costs along the path.
276+
* Cost acts as a threshold. When only one path exists, traffic flows on that
277+
path regardless of cost. If a target becomes unavailable, traffic moves to
278+
the remaining path regardless of cost.
279+
* When multiple paths exist, traffic flows on the lowest-cost path until the
280+
number of open connections exceeds the cost of an alternative path. After
281+
that threshold is reached, new connections are spread across both paths.
282+
* Traffic distribution is statistical, not round robin.
283+
284+
The following procedure describes how to set link cost in various scenarios:
285+
286+
**Procedure**
287+
288+
1. To issue a token and specify the cost:
289+
290+
```bash
291+
skupper token issue <filename> --cost <integer-cost>
292+
```
293+
where `<integer-cost>` is a positive integer (minimum `1`) and traffic favors
294+
lower-cost links.
295+
296+
For example, to issue a token and set the link cost to `2`:
297+
```
298+
skupper token issue token.yaml --cost 2
299+
```
300+
301+
302+
2. To update the cost on an existing link:
303+
304+
```
305+
skupper link update <link-name> --cost <integer-cost>
306+
```
307+
For example:
308+
```
309+
skupper link update west-6bfn6 --cost 2
310+
Waiting for status...
311+
Link "west-6bfn6" is ready.
312+
```
313+
314+
3. To check the cost of a specific link:
315+
316+
```
317+
skupper link status <link-name>
318+
```
319+
Example output:
320+
```
321+
Name: west-6bfn6
322+
Status: Ready
323+
Cost: 2
324+
Message: <none>
325+
```
326+
327+
**Additional information**
328+
329+
A common use case for link cost is automatic failover.
330+
You can configure a primary site with an effective cost of `0` (local) and a
331+
backup site with a high link cost, for example `99999`:
332+
333+
- local server — effective cost `0`
334+
- remote backup server — link cost `99999`
335+
336+
In this configuration, all connections are routed to the local server.
337+
If the local server becomes unavailable, traffic fails over to the remote
338+
server regardless of the high cost.
339+
340+
**📌 NOTE**
341+
Skupper does not provide orchestrated failover for stateful applications that
342+
require control over the order in which traffic is redirected.
343+
You must implement that orchestration separately.
344+
345+
For per-service failover or weighted traffic distribution, use a
346+
[multi-key listener][mkl] instead.
347+
348+
[mkl]: ../kube-yaml/service-exposure.html#kube-creating-multikeylistener-yaml

input/kube-yaml/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ You can use YAML on Kubernetes after installing the Skupper controller to create
66

77
* [Create sites][site-configuration]
88
* [Link sites][site-linking] (requires that one site has link access enabled)
9+
* [Configure link cost][link-cost]
910
* [Expose and consume services][service-exposure]
1011

1112
[site-configuration]: ./site-configuration.html
1213
[site-linking]: ./site-linking.html
14+
[link-cost]: ./site-linking.html#kube-link-cost-yaml
1315
[service-exposure]: ./service-exposure.html

input/kube-yaml/service-exposure.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ There are many options to consider when creating connectors using YAML, see [Con
4040
```
4141
This creates a connector in the `east` site and exposes the `backend` deployment on the network on port 8080.
4242
You can create a listener on a different site using the matching routing key `backend` to address this service.
43-
43+
4444
To create the connector resource:
4545

4646
```bash
@@ -95,7 +95,7 @@ For configuration details, see [Listener resource][listener-resource].
9595
```
9696
This creates a listener in the `west` site and matches with the connector that uses the routing key `backend`.
9797
It also creates a service named `east-backend` exposed on port 8080 in the current namespace.
98-
98+
9999
To create the listener resource:
100100

101101
```bash
@@ -128,10 +128,11 @@ Use a multi-key listener when you want one service endpoint to aggregate traffic
128128

129129
With multi-key listeners, you must choose a strategy which determines how the traffic is distributed:
130130

131-
* priority - Uses the first routing key in list that is available for traffic. If the connector becomes unavailable, the listener matches with the next available routing key in list.
131+
* priority - Uses the first routing key in list that is available for traffic. If the connectors for that routing key become unavailable, the listener matches with the next routing key in list.
132132
* weighted - Uses the routing keys in proportion to the assigned weights. For example, if `backend1` is assigned 25 and `backend2` is assigned 75, then only a quarter of the TCP connections are directed to `backend1`.
133133

134-
Multi-key listeners provide predictable traffic distribution from the client side and typically are not influenced by link costs.
134+
**📌 NOTE**
135+
Multi-key listeners select between routing keys using the configured strategy. Each routing key may have multiple connectors, and link cost determines which connector is used within each routing key. The two mechanisms are independent.
135136

136137
For configuration details, see [MultiKeyListener resource][multikeylistener-resource].
137138

@@ -146,7 +147,6 @@ For configuration details, see [MultiKeyListener resource][multikeylistener-reso
146147

147148
2. Determine which strategy is best for your use case. For example, failover is best achieved using the `priority` strategy.
148149

149-
150150
3. Create a multi-key listener resource YAML file.
151151
For example:
152152
```yaml
@@ -163,8 +163,8 @@ For configuration details, see [MultiKeyListener resource][multikeylistener-reso
163163
east-backend: 1
164164
west-backend: 1
165165
```
166-
This creates a listener named `mkl-backend` that exposes a single endpoint on port 9092 and distributes traffic evenly across the `east-backend` and `west-backend` routing keys.
167-
166+
This creates a listener named `mkl-backend` that exposes a single endpoint on port 9092 and distributes traffic evenly between the `east-backend` and `west-backend` routing keys. Each routing key may have multiple connectors; link cost determines which connector is used within each routing key.
167+
168168
To prefer one routing key first and fall back to another, use the `priority` strategy:
169169
```yaml
170170
apiVersion: skupper.io/v2alpha1
@@ -180,13 +180,10 @@ For configuration details, see [MultiKeyListener resource][multikeylistener-reso
180180
- east-backend-http
181181
- west-backend-http
182182
```
183-
184183
To create the multi-key listener resource:
185-
186184
```bash
187185
kubectl apply -f <filename>
188186
```
189-
190187
where `<filename>` is the name of a YAML file that is saved on your local filesystem.
191188

192189
4. Check the multi-key listener status:

input/kube-yaml/site-linking.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,147 @@ A connecting site redeems this token for a `Link` resource to establish a link t
122122
NAME STATUS REMOTE SITE MESSAGE
123123
token-to-west Ready my-site OK
124124
```
125+
126+
<a id="kube-link-cost-yaml"></a>
127+
## Specifying link cost using YAML
128+
<!--PROCEDURE-->
129+
130+
Link cost is a configurable integer value that influences how Skupper routes
131+
traffic across links between sites.
132+
The routing algorithm favors paths with the lowest total cost from client to
133+
target server.
134+
135+
**📌 NOTE**
136+
For most load-balancing and failover use cases, a [multi-key listener][mkl]
137+
provides more predictable, per-service control than link cost.
138+
Link cost applies to **all services** that traverse a link; it is not
139+
possible to set different costs for distinct services on the same link.
140+
141+
Understanding link cost behavior:
142+
143+
* The default link cost is `1`. Local workloads have an implicit cost of `0`.
144+
* If a connection traverses more than one link, the path cost is the sum of
145+
all link costs along the path.
146+
* Cost acts as a threshold. When only one path exists, traffic flows on that
147+
path regardless of cost. If a target becomes unavailable, traffic moves to
148+
the remaining path regardless of cost.
149+
* When multiple paths exist, traffic flows on the lowest-cost path until the
150+
number of open connections exceeds the cost of an alternative path. After
151+
that threshold is reached, new connections are spread across both paths.
152+
* Traffic distribution is statistical, not round robin.
153+
154+
Link cost is set on the `Link` custom resource via `spec.cost`.
155+
The `AccessToken` resource also exposes `spec.linkCost`, which is applied to the `Link` created when the token is redeemed.
156+
157+
**Prerequisites**
158+
159+
* Two or more linked sites.
160+
* The name of the `Link` resource whose cost you want to set.
161+
162+
**Procedure**
163+
164+
**Option A — Set cost when redeeming a token**
165+
166+
Add `linkCost` to the `AccessToken` resource before applying it. When the token is redeemed, the resulting `Link` is created with that cost.
167+
168+
```yaml
169+
apiVersion: skupper.io/v2alpha1
170+
kind: AccessToken
171+
metadata:
172+
name: my-token
173+
spec:
174+
url: <grant-url>
175+
code: <secret-code>
176+
ca: <ca-cert>
177+
linkCost: 2
178+
```
179+
180+
Apply it:
181+
182+
```bash
183+
kubectl apply -f token.yaml
184+
```
185+
186+
**Option B — Update cost on an existing link**
187+
188+
1. Find the link name:
189+
190+
```bash
191+
kubectl get links
192+
```
193+
Example output:
194+
```
195+
NAME STATUS REMOTE SITE MESSAGE
196+
west-6bfn6 Ready west
197+
```
198+
199+
2. Patch the cost on the link:
200+
201+
```bash
202+
kubectl patch link west-6bfn6 --type merge -p '{"spec":{"cost":2}}'
203+
```
204+
205+
Or edit the resource directly:
206+
207+
```bash
208+
kubectl edit link west-6bfn6
209+
```
210+
211+
Set the `cost` field in `spec`:
212+
213+
```yaml
214+
apiVersion: skupper.io/v2alpha1
215+
kind: Link
216+
metadata:
217+
name: west-6bfn6
218+
spec:
219+
cost: 2
220+
endpoints:
221+
- host: <remote-host>
222+
name: inter-router
223+
port: "55671"
224+
- host: <remote-host>
225+
name: edge
226+
port: "45671"
227+
tlsCredentials: west-6bfn6
228+
```
229+
230+
**Verifying link cost**
231+
232+
Check the cost of a specific link:
233+
234+
```bash
235+
kubectl get link west-6bfn6 -o yaml
236+
```
237+
238+
Look for `spec.cost` in the output. Alternatively, for a summary:
239+
240+
```bash
241+
kubectl get links
242+
```
243+
244+
**Additional information**
245+
246+
* The minimum enforced cost is `1`. If `spec.cost` is set to `0` or omitted, the router treats it as `1`.
247+
* For the failover pattern (primary cost `0`/local, backup cost `99999`), set `spec.cost: 99999` on the backup site's `Link` resource.
248+
249+
A common use case for link cost is automatic failover.
250+
You can configure a primary site with an effective cost of `0` (local) and a
251+
backup site with a high link cost, for example `99999`:
252+
253+
- local server — effective cost `0`
254+
- remote backup server — link cost `99999`
255+
256+
In this configuration, all connections are routed to the local server.
257+
If the local server becomes unavailable, traffic fails over to the remote
258+
server regardless of the high cost.
259+
260+
**📌 NOTE**
261+
Skupper does not provide orchestrated failover for stateful applications that
262+
require control over the order in which traffic is redirected.
263+
You must implement that orchestration separately.
264+
265+
For per-service failover or weighted traffic distribution, use a
266+
[multi-key listener][mkl] instead.
267+
268+
[mkl]: ./service-exposure.html#kube-creating-multikeylistener-yaml

0 commit comments

Comments
 (0)