TIS1103 - Weight Assumed as 100 for a Single Route Destination
The weight is automatically assumed to be 100 because there is only one route destination defined in the VirtualService
.
weight
FieldTo reduce unnecessary configuration, remove the weight
field for a single route destination. Alternatively, add more route destinations with specific weights to achieve load balancing.
Examples
-
VirtualService
with Unnecessary Weight Set to 100 for a Single DestinationapiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-virtual-service
namespace: example-namespace
spec:
hosts:
- "my-app.example.com"
http:
- route:
- destination:
host: "my-app-service.example-namespace.svc.cluster.local"
weight: 100Explanation: Since there is only one route destination in the
VirtualService
, specifying a weight of 100 is redundant. Istio automatically assigns a weight of 100 when there is only one destination, which means theweight
field is unnecessary in this case.
Recommendation
Remove the weight
field or add another RouteDestination
with a specific weight to create a load balancing scenario.
-
Remove the
weight
Field for a Single DestinationIf only one destination is needed, remove the
weight
field to simplify the configuration.apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-virtual-service
namespace: example-namespace
spec:
hosts:
- "my-app.example.com"
http:
- route:
- destination:
host: "my-app-service.example-namespace.svc.cluster.local"Explanation: Removing the
weight
field reduces unnecessary complexity, as Istio will automatically assign a weight of 100 for the only available destination. -
Add Another Route Destination for Load Balancing
If multiple destinations are needed, add another
RouteDestination
with specific weights to distribute traffic.apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-virtual-service
namespace: example-namespace
spec:
hosts:
- "my-app.example.com"
http:
- route:
- destination:
host: "my-app-service-v1.example-namespace.svc.cluster.local"
weight: 50
- destination:
host: "my-app-service-v2.example-namespace.svc.cluster.local"
weight: 50Explanation: Adding another route destination with specified weights creates a load balancing setup where traffic is distributed between multiple versions of the service.