Introduction
Istio VirtualService route matching fails when host or path conditions do not match incoming requests. This guide provides step-by-step diagnosis and resolution with specific commands and configuration examples.
Symptoms
Typical symptoms and error messages when this issue occurs:
HTTP 404 Not Found
VirtualService route not matched
No route matched for host: api.example.comObservable indicators: - Service mesh proxy logs show configuration errors - Control plane reports validation failures - Traffic routing does not match expected behavior
Common Causes
- 1.Routing issues are typically caused by:
- 2.Host header not matching VirtualService configuration
- 3.Missing or incorrect DestinationRule subset
- 4.Gateway not bound to VirtualService
- 5.Priority order of multiple VirtualServices
Step-by-Step Fix
Step 1: Check Current State
istioctl analyzeStep 2: Identify Root Cause
kubectl get virtualservice,destinationrule,gateway -AStep 3: Apply Primary Fix
# Correct VirtualService configuration
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: my-service
spec:
hosts:
- "api.example.com" # Must match request Host header
gateways:
- my-gateway # Must reference existing Gateway
http:
- match:
- uri:
prefix: "/api"
route:
- destination:
host: my-service # Must match service name
subset: v1 # Must match DestinationRule subsetApply this configuration:
kubectl apply -f virtualservice.yamlStep 4: Apply Alternative Fix (If Needed)
```bash # Debug VirtualService routing istioctl proxy-config routes <pod-name> -o json | jq '.[].routeConfig.virtualHosts[]'
# Check if host matches curl -H "Host: api.example.com" http://<gateway-ip>/api/test
# Verify DestinationRule kubectl get destinationrule -A -o yaml ```
Step 5: Verify the Fix
After applying the fix, verify with:
istioctl analyze && kubectl exec <pod> -c istio-proxy -- curl -s localhost:15000/readyExpected output should show healthy proxies and correct routing.
Common Pitfalls
- VirtualService hosts not matching Gateway servers
- DestinationRule subset labels not matching pod labels
- TLS Secret in wrong namespace
- Missing Gateway binding in VirtualService
Best Practices
- Use istioctl analyze before applying changes
- Label services with version for subset routing
- Keep VirtualService and DestinationRule in same namespace as service
- Use ServiceEntry for external services
Related Issues
- Istio Gateway TLS Secret Missing
- Istio Sidecar Injection Disabled
- Istio Authorization Policy Deny All
- Istio Circuit Breaker Issues