This document describes how to create DNSChaos experiments in Chaos Mesh to simulate DNS faults.
DNSChaos is used to simulate wrong DNS responses. For example, DNSChaos can return an error or return a random IP address when receiving a DNS request.
Before creating a DNSChaos experiment using Chaos Mesh, you need to deploy a special DNS service to inject faults:
After executing the above commands, check if the DNS service status is normal:
kubectl get pods -n chaos-testing -l app.kubernetes.io/component=chaos-dns-server
Make sure that the Pod status is
Currently, DNSChaos only supports record types
The chaos DNS service runs CoreDNS with the k8s_dns_chaos plugin. If the CoreDNS service in your Kubernetes cluster contains some special configurations, you can edit configMap
dns-server-configto make the configuration of the chaos DNS service consistent with that of the K8s CoreDNS service using the following command:
kubectl edit configmap dns-server-config -n chaos-testing
Open Chaos Dashboard, and click NEW EXPERIMENT on the page to create a new experiment:
In the Choose a Target area, choose DNS FAULT and select a specific behavior, such as ERROR. Then fill out the matching rules.
According to the matching rules configured in the screenshot, the DNS FAULT takes effect for domains including
github.com, which means that an error will be returned when a DNS request is sent to these three domains. For details of specific matching rules, refer to the description of the
patternsfield in Configuration Description.
Fill out the experiment information, and specify the experiment scope and the scheduled experiment duration:
Submit the experiment information.
Write the experiment configuration to the
apiVersion: chaos-mesh.org/v1alpha1kind: DNSChaosmetadata: name: dns-chaos-example namespace: chaos-testingspec: action: random mode: all patterns: - google.com - chaos-mesh.* - github.?om selector: namespaces: - busybox
This configuration can take effect for domains including
github.com, which means that an IP address will be returned when a DNS request is sent to these three domains. For specific matching rules, refer to the
patternsdescription in Configuration Description.
After the configuration file is prepared, use
kubectlto create an experiment:
kubectl apply -f dnschaos.yaml
|action||string||Defines the behavior of DNS fault. The value can be ||None||Yes|
|patterns||String array||Selects a domain template that matches faults. Placeholder ||||No|
|mode||string||Specifies the mode of the experiment. The mode options include ||None||Yes|
|value||string||Provides parameters for the ||None||No||2|
|selector||struct||Specifies the target Pod. For details, refer to Define the Scope of Chaos Experiments.||None||Yes|
The wildcard in
patternsconfiguration must be at the end of string. For example,
chaos-mes*.org.is an invalid configuration.
patternsis not configured, faults will be injected for all domains.