NAME

IO::K8s::Role::Loadbalanced - Role for traffic distribution (weighted backends, mirroring)

VERSION

version 1.111

SYNOPSIS

package My::Route;
use IO::K8s::APIObject api_version => 'example.com/v1';
with 'IO::K8s::Role::Loadbalanced';

package main;
my $r = My::Route->new;
$r->set_weighted('canary', 10)->set_weighted('stable', 90)
  ->mirror_to('shadow', percent => 1);

DESCRIPTION

This role provides the two traffic-distribution operations documented in the README's fluent-API section: weighted backend fan-out and traffic mirroring. Both write through IO::K8s::Role::SpecBuilder's spec_* methods, so the role composes cleanly with CRD classes whose spec is either a hash or a typed object.

Apply this role to a custom CRD class that exposes the same weighted.services / mirroring.mirrors shape on the wire. The Istio DestinationRule CRD and the Gateway API TCPRoute spec both fit this shape without changes; arbitrary CRDs may need their own adaptation.

set_weighted

$obj->set_weighted($name, $weight);

Upserts a weighted backend into spec.weighted.services. If a backend with name => $name already exists its weight is replaced; otherwise the { name => $name, weight => $weight } entry is appended. The shape matches Istio's DestinationRule trafficPolicy weighted subset semantics -- useful when a CRD consumer wants the same UX across several traffic-management kinds. Returns $self for chaining.

$route->set_weighted('api-v1', 90)->set_weighted('api-v2', 10);

mirror_to

$obj->mirror_to($name, percent => $percent);

Appends a mirror entry under spec.mirroring.mirrors that sends a percentage of traffic (percent, 1-100) to the named backend. percent is optional -- when omitted the entry has no percent field and the consumer decides the default. Mirroring entries are appended; the method does not de-duplicate. Returns $self for chaining.

$route->mirror_to('shadow', percent => 5);

SEE ALSO

IO::K8s::Role::Routable, IO::K8s::Role::SpecBuilder, IO::K8s::APIObject

SUPPORT

Issues

Please report bugs and feature requests on GitHub at https://github.com/pplu/io-k8s-p5/issues.

CONTRIBUTING

Contributions are welcome! Please fork the repository and submit a pull request.

AUTHORS

  • Torsten Raudssus <getty@cpan.org>

  • Jose Luis Martinez Torres <jlmartin@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2018-2026 by Jose Luis Martinez Torres <jlmartin@cpan.org>.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004