Both VirtualService and EnvoyFilter in Service Mesh (ASM) can customize request and response headers, but they differ in flexibility and use scenarios.
Comparison between VirtualService and EnvoyFilter
VirtualService is better suited for simple, routing-related header modifications, whereas EnvoyFilter allows deeper customization of Envoy proxies. Choose between them based on your requirements and the comparisons in the following table.
|
Item |
VirtualService |
EnvoyFilter |
|
Abstraction level |
Provides a higher-level abstraction that lets you define the addition or removal of request and response headers directly in Istio routing rules. This is the recommended approach because the rules are easier to understand and configure. |
Provides a lower-level interface for directly managing Envoy proxy configurations. EnvoyFilter lets you write custom Lua scripts or use other Envoy extensions to implement complex logic. This method is more powerful and flexible, but requires a deeper understanding of Envoy configurations. |
|
Usability |
Uses standard Istio CRDs, making it easier to configure and understand. |
Configuration is more complex and requires familiarity with the Envoy configuration API. Errors are more likely to occur without a good understanding of Envoy internals. |
|
Applicable scope |
Covers most common header operations: adding, modifying, or deleting request and response headers. You can set header values to fixed strings or dynamically generate values by using built-in expressions. These expressions are enclosed in the |
Supports advanced customization and complex operations beyond what VirtualService offers, such as condition checks, complex data transformations, or calls to external services. Header values can be dynamically computed through code. |
|
Use scenarios |
You only need to add, remove, or modify headers, and the operations are tied to specific routing rules. |
You need to perform in-depth request or response manipulation, or modify headers globally without changing Istio routing rules. |