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
-
VirtualServicewith 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 theweightfield 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
weightField for a Single DestinationIf only one destination is needed, remove the
weightfield 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
weightfield 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
RouteDestinationwith 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.