Skip to main content

Fault Injection

Fault injection is a service mesh feature that deliberately adds delays or error responses to traffic so you can test how services behave when dependencies fail, without changing application code. In Istio it is set in a VirtualService fault block.

Why inject faults

Real failures are discovered at 2am. Fault injection lets you rehearse them safely: does the caller time out, retry sensibly, trip its circuit breaker, and degrade gracefully? Because the proxy introduces the fault, you test the real binaries with their real client settings.

flowchart TD C["Calling service"] --> P["Sidecar proxy"] P -->|"delay fault"| D["Add latency
then forward"] P -->|"abort fault"| A["Return error
no forwarding"] D --> T["Target service"] classDef svc fill:#D1FAE5,color:#1E293B classDef proxy fill:#DBEAFE,color:#1E293B classDef fault fill:#FEE2E2,color:#1E293B class C,T svc class P proxy class D,A fault

Delay and abort

YAML
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: payments-service
namespace: staging
spec:
hosts:
- payments-service
http:
- fault:
delay:
percentage:
value: 10.0
fixedDelay: 5s
abort:
percentage:
value: 5.0
httpStatus: 503
route:
- destination:
host: payments-service

Here 10 percent of requests get 5 seconds of delay and 5 percent are aborted with a 503.

A resilience test recipe

  • Configure outlier detection in the DestinationRule.
  • Abort 100 percent of requests to one test workload with 503.
  • Confirm the circuit breaker ejects it, then remove the fault and confirm recovery.
Remember

A VirtualService fault applies to every matching caller. Use a test namespace or low percentages and, where possible, match on a test header.

Security

Never leave a fault block in a production VirtualService after a test. It looks like ordinary routing configuration and is easy to forget.

Tip

Match on a header such as x-chaos: true so only your test requests are affected.

Frequently Asked Questions

Which fault types can a mesh inject?

Istio supports delay faults, which add latency before forwarding, and abort faults, which return a chosen HTTP or gRPC status without forwarding. Both can target a percentage of traffic.

Why test at the mesh and not with mocks?

Mocks check code intent. Mesh-level faults exercise the real timeouts, retries, and connection pools of the real client under injected conditions.

Do all meshes support it?

No. Istio does natively. Linkerd does not provide built-in fault injection, so teams use external chaos tools there.

Found a mistake, an outdated step or a broken link?