MeshFaultInjection (beta)

With the MeshFaultInjection policy you can easily test your microservices against resiliency.

This policy uses a new policy matching algorithm and is in beta state. It should not be combined with FaultInjection.

targetRef support matrix

targetRef.kindtop leveltofrom
Mesh
MeshSubset
MeshService
MeshServiceSubset

To learn more about the information in this table, see the matching docs.

Configuration

MeshFaultInjection allows configuring a list of HTTP faults. They execute in the same order as they were defined.

  1. default:
  2. http:
  3. - abort:
  4. httpStatus: 500
  5. percentage: "2.5"
  6. delay:
  7. value: 5s
  8. percentage: 5
  9. responseBandwidth:
  10. limit: "50mbps"
  11. percentage: 50
  12. - abort:
  13. httpStatus: 500
  14. percentage: 10
  15. - delay:
  16. value: 5s
  17. percentage: 5

It’s worth mentioning that percentage of the next filter depends on the percentage of previous ones.

  1. http:
  2. - abort:
  3. httpStatus: 500
  4. percentage: 70
  5. - abort:
  6. httpStatus: 503
  7. percentage: 50

That means that for 70% of requests, it returns 500 and for 50% of the 30% that passed it returns 503.

Abort

Abort defines a configuration of not delivering requests to destination service and replacing the responses from destination dataplane by predefined status code.

  • httpStatus - HTTP status code which will be returned to source side, has to be in [100 - 599] range
  • percentage - a percentage of requests on which abort will be injected, has to be in [0.0 - 100.0] range. If the value is a double number, put it in quotes.

Delay

Delay defines a configuration of delaying a response from a destination.

  • value - the duration during which the response will be delayed
  • percentage - a percentage of requests on which abort will be injected, has to be in [0.0 - 100.0] range. If the value is a double number, put it in quotes.

ResponseBandwidth limit

ResponseBandwidth defines a configuration to limit the speed of responding to requests.

  • limit - represented by value measure in gbps, mbps, kbps, or bps, e.g. 10kbps
  • percentage - a percentage of requests on which abort will be injected, has to be in [0.0 - 100.0] range. If the value is a double number, put it in quotes.

Examples

Service backend returns 500 for 50% of requests from frontend service

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshFaultInjection
  3. metadata:
  4. name: default
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default # optional, defaults to `default` if it isn't configured
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: backend
  12. from:
  13. - targetRef:
  14. kind: MeshService
  15. name: frontend
  16. default:
  17. http:
  18. - abort:
  19. httpStatus: 500
  20. percentage: 50

Apply the configuration with kubectl apply -f [..].

  1. type: MeshFaultInjection
  2. mesh: default
  3. name: default-fault-injection
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: MeshService
  11. name: frontend
  12. default:
  13. http:
  14. - abort:
  15. httpStatus: 500
  16. percentage: 50

Apply the configuration with kumactl apply -f [..] or with the HTTP API.

50.5% of requests to service backend from any service is going to be delayed by 5s

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshFaultInjection
  3. metadata:
  4. name: default
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default # optional, defaults to `default` if it isn't configured
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: backend
  12. from:
  13. - targetRef:
  14. kind: MeshService
  15. name: frontend
  16. default:
  17. http:
  18. - delay:
  19. percentage: "50.5"
  20. value: 5s

Apply the configuration with kubectl apply -f [..].

  1. type: MeshFaultInjection
  2. mesh: default
  3. name: default-fault-injection
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: Mesh
  11. name: default
  12. default:
  13. http:
  14. - delay:
  15. percentage: "50.5"
  16. value: 5s

Apply the configuration with kumactl apply -f [..] or with the HTTP API.

Backend service with a list of faults that are applied for frontend service

  1. apiVersion: kuma.io/v1alpha1
  2. kind: MeshFaultInjection
  3. metadata:
  4. name: default
  5. namespace: kuma-system
  6. labels:
  7. kuma.io/mesh: default # optional, defaults to `default` if it isn't configured
  8. spec:
  9. targetRef:
  10. kind: MeshService
  11. name: backend
  12. from:
  13. - targetRef:
  14. kind: MeshService
  15. name: frontend
  16. default:
  17. http:
  18. - abort:
  19. httpStatus: 500
  20. percentage: "2.5"
  21. - abort:
  22. httpStatus: 500
  23. percentage: 10
  24. - delay:
  25. value: 5s
  26. percentage: 5

Apply the configuration with kubectl apply -f [..].

  1. type: MeshFaultInjection
  2. mesh: default
  3. name: default-fault-injection
  4. spec:
  5. targetRef:
  6. kind: MeshService
  7. name: backend
  8. from:
  9. - targetRef:
  10. kind: MeshService
  11. name: frontend
  12. default:
  13. http:
  14. - abort:
  15. httpStatus: 500
  16. percentage: "2.5"
  17. - abort:
  18. httpStatus: 500
  19. percentage: 10
  20. - delay:
  21. value: 5s
  22. percentage: 5

Apply the configuration with kumactl apply -f [..] or with the HTTP API.

All policy options