7.6 KiB
| id | title | sidebar_label | original_id |
|---|---|---|---|
| version-1.6.0-pod-network-latency | Pod Network Latency Experiment Details | Pod Network Latency | pod-network-latency |
| Type | Description | Tested K8s Platform |
|---|---|---|
| Generic | Inject Network Latency Into Application Pod | GKE, Packet(Kubeadm), EKS, Minikube, AKS > v1.6.0 |
kubectl get pods in operator namespace (typically, litmus). If not, install from here
- Ensure that the pod-network-latency experiment resource is available in the cluster by executing kubectl get chaosexperiments in the desired namespace. . If not, install from here
apiVersion: v1 kind: ServiceAccount metadata: name: pod-network-latency-sa namespace: default labels: name: pod-network-latency-sa
apiVersion: rbac.authorization.k8s.io/v1beta1 kind: Role metadata: name: pod-network-latency-sa namespace: default labels: name: pod-network-latency-sa rules:
- apiGroups: ["","litmuschaos.io","batch"] resources: ["pods","jobs","pods/log","events","chaosengines","chaosexperiments","chaosresults"] verbs: ["create","list","get","patch","update","delete"]
apiVersion: rbac.authorization.k8s.io/v1beta1 kind: RoleBinding metadata: name: pod-network-latency-sa namespace: default labels: name: pod-network-latency-sa roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: pod-network-latency-sa subjects:
- kind: ServiceAccount name: pod-network-latency-sa namespace: default
### Prepare ChaosEngine
- Provide the application info in `spec.appinfo`
- Override the experiment tunables if desired in `experiments.spec.components.env`
- To understand the values to provided in a ChaosEngine specification, refer [ChaosEngine Concepts](chaosengine-concepts.md)
#### Supported Experiment Tunables
<table>
<tr>
<th> Variables </th>
<th> Description </th>
<th> Type </th>
<th> Notes </th>
</tr>
<tr>
<td> NETWORK_INTERFACE </td>
<td> Name of ethernet interface considered for shaping traffic </td>
<td> Mandatory </td>
<td> </td>
</tr>
<tr>
<td> TARGET_CONTAINER </td>
<td> Name of container which is subjected to network latency </td>
<td> Mandatory </td>
<td> </td>
</tr>
<tr>
<td> NETWORK_LATENCY </td>
<td> The latency/delay in milliseconds </td>
<td> Optional </td>
<td> Default (60000ms) </td>
</tr>
<tr>
<td> TOTAL_CHAOS_DURATION </td>
<td> The time duration for chaos insertion (seconds) </td>
<td> Optional </td>
<td> Default (60000ms) </td>
</tr>
<tr>
<td> LIB </td>
<td> The chaos lib used to inject the chaos </td>
<td> Optional </td>
<td> only `pumba` supported currently </td>
</tr>
<tr>
<td> LIB_IMAGE </td>
<td> The pumba image used to run the kill command </td>
<td> Optional </td>
<td> Defaults to `gaiaadm/pumba:0.6.5` </td>
</tr>
<tr>
<td> RAMP_TIME </td>
<td> Period to wait before and after injection of chaos in sec </td>
<td> Optional </td>
<td> </td>
</tr>
<tr>
<td> INSTANCE_ID </td>
<td> A user-defined string that holds metadata/info about current run/instance of chaos. Ex: 04-05-2020-9-00. This string is appended as suffix in the chaosresult CR name.</td>
<td> Ensure that the overall length of the chaosresult CR is still < 64 characters </td>
<td> </td>
</tr>
</table>
#### Sample ChaosEngine Manifest
[embedmd]:# (https://raw.githubusercontent.com/litmuschaos/chaos-charts/master/charts/generic/pod-network-latency/engine.yaml yaml)
```yaml
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: nginx-network-chaos
namespace: default
spec:
# It can be delete/retain
jobCleanUpPolicy: 'delete'
# It can be true/false
annotationCheck: 'true'
# It can be active/stop
engineState: 'active'
#ex. values: ns1:name=percona,ns2:run=nginx
auxiliaryAppInfo: ''
monitoring: false
appinfo:
appns: 'default'
# FYI, To see app label, apply kubectl get pods --show-labels
applabel: 'app=nginx'
appkind: 'deployment'
chaosServiceAccount: pod-network-latency-sa
experiments:
- name: pod-network-latency
spec:
components:
env:
#Container name where chaos has to be injected
- name: TARGET_CONTAINER
value: 'nginx'
#Network interface inside target container
- name: NETWORK_INTERFACE
value: 'eth0'
- name: LIB_IMAGE
value: 'gaiaadm/pumba:0.6.5'
- name: NETWORK_LATENCY
value: '60000'
- name: TOTAL_CHAOS_DURATION
value: '60' # in seconds
Create the ChaosEngine Resource
-
Create the ChaosEngine manifest prepared in the previous step to trigger the Chaos.
kubectl apply -f chaosengine.yml -
If the chaos experiment is not executed, refer to the troubleshooting section to identify the root cause and fix the issues.
Watch Chaos progress
-
View network latency by setting up a ping on the affected pod from the cluster nodes
ping <pod_ip_address>
Check Chaos Experiment Result
-
Check whether the application is resilient to the Pod Network Latency, once the experiment (job) is completed. The ChaosResult resource name is derived like this:
<ChaosEngine-Name>-<ChaosExperiment-Name>.kubectl describe chaosresult <ChaosEngine-Name>-<ChaosExperiment-Name> -n <application-namespace>
Application Pod Network Latency Demo
- A sample recording of this experiment execution is provided here.