Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/testing-guides/injecting-faults-with-xk6-disruptor/xk6-disruptor/poddisruptor/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
PodDisruptor
The PodDisruptor class can inject different types of faults into the pods that match a selection criteria.
To construct a PodDisruptor, use the
PodDisruptor() constructor.
Methods
| Method | Description |
|---|---|
| PodDisruptor.injectGrpcFaults() | Inject gRPC faults in the target Pods |
| PodDisruptor.injectHTTPFaults() | Inject HTTP faults in the target Pods |
| PodDisruptor.targets() | Returns the list of target Pods of the PodDisruptor |
| PodDisruptor.terminatePods() | executes a Pod Termination fault in the target Pods |
Example
This example:
- Creates a selector that matches all pods in the
defaultnamespace with therun=nginxlabel - Injects a delay of 100ms and makes 10 percent of requests return an http response code
500.
import { PodDisruptor } from 'k6/x/disruptor';
const selector = {
namespace: 'default',
select: {
labels: {
run: 'nginx',
},
},
};
const fault = {
averageDelay: '100ms',
errorRate: 0.1,
errorCode: 500,
};
export default function () {
const disruptor = new PodDisruptor(selector);
disruptor.injectHTTPFaults(fault, '30s');
}Note
You can test this script by first creating a pod running nginx with the command below, assuming you have kubectl installed in your environment:
Bashkubectl run nginx --image=nginxYou can also use the xk6-kubernetes extension for creating these resources from your test script.
Was this page helpful?
Related resources from Grafana Labs

