Pod HTTP modify header
Pod HTTP modify header is a Kubernetes pod-level chaos fault that injects chaos on the service whose port is provided using the TARGET_SERVICE_PORT
environment variable.
- This is done by starting the proxy server and redirecting the traffic through the proxy server.
- It can cause modification of headers of requests and responses of the service. This can be used to test service resilience towards incorrect or incomplete headers.
Usage
View fault usage
Prerequisites
- Kubernetes> 1.16.
Default validations
The application pods should be in running state before and after chaos injection.
Fault tunables
Fault tunables
Mandatory Fields
Variables | Description | Notes |
---|---|---|
TARGET_SERVICE_PORT | Port of the service to target | Defaults to port 80 |
HEADERS_MAP | Map of headers to modify/add | For example, {"X-Litmus-Test-Header": "X-Litmus-Test-Value"}. To remove a header, just set the value to ""; For example, {"X-Litmus-Test-Header": ""} |
HEADER_MODE | Whether to modify response headers or request headers. Accepted values: request, response | Defaults to response |
Optional fields
Variables | Description | Notes |
---|---|---|
PROXY_PORT | Port where the proxy will be listening for requests | Defaults to 20000 |
NETWORK_INTERFACE | Network interface to be used for the proxy | Defaults to `eth0` |
TOXICITY | Percentage of HTTP requests to be affected | Defaults to 100 |
CONTAINER_RUNTIME | container runtime interface for the cluster | Defaults to docker, supported values: docker, containerd and crio for litmus and only docker for pumba LIB |
SOCKET_PATH | Path of the containerd/crio/docker socket file | Defaults to `/var/run/docker.sock` |
TOTAL_CHAOS_DURATION | The duration of chaos injection (seconds) | Default (60s) |
TARGET_PODS | Comma separated list of application pod name subjected to pod http modify header chaos | If not provided, it will select target pods randomly based on provided appLabels |
PODS_AFFECTED_PERC | The Percentage of total pods to target | Defaults to 0 (corresponds to 1 replica), provide numeric value only |
LIB_IMAGE | Image used to run the netem command | Defaults to `litmuschaos/go-runner:latest` |
RAMP_TIME | Period to wait before and after injection of chaos in sec | For example, 30 |
SEQUENCE | It defines sequence of chaos execution for multiple target pods | Default value: parallel. Supported: serial, parallel |
Fault examples
Common and pod-specific tunables
Refer to the common attributes and pod-specific tunables to tune the common tunables for all fault and pod specific tunables.
Target service port
It defines the port of the targeted service that is being targeted. It can be tuned via TARGET_SERVICE_PORT
ENV.
Use the following example to tune this:
## provide the port of the targeted service
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
# map of headers to modify/add
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'
Proxy port
It defines the port on which the proxy server will listen for requests. It can be tuned via PROXY_PORT
Use the following example to tune this:
## provide the port for proxy server
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# provide the port for proxy server
- name: PROXY_PORT
value: "8080"
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
# map of headers to modify/add
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'
Headers map
It is the map of headers that are to be modified or added to the Http request/response. It can be tuned via HEADERS_MAP
ENV.
Use the following example to tune this:
## provide the headers as a map
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# map of headers to modify/add; Eg: {"X-Litmus-Test-Header": "X-Litmus-Test-Value"}
# to remove a header, just set the value to ""; Eg: {"X-Litmus-Test-Header": ""}
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
Header mode
It defined whether the request or the response header has to be modified. It can be tuned via HEADER_MODE
ENV.
Use the following example to tune this:
## provide the mode of the header modification; request/response
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# whether to modify response headers or request headers. Accepted values: request, response
- name: HEADER_MODE
value: "response"
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
# map of headers to modify/add
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'
Toxicity
It defines the toxicity value to be added to the http request. It can be tuned via TOXICITY
environment variable.
Toxicity value defines the percentage of the total number of http requests to be affected.
Use the following example to tune this:
## provide the toxicity
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-modify-header
spec:
components:
env:
# toxicity is the probability of the request to be affected
# provide the percentage value in the range of 0-100
# 0 means no request will be affected and 100 means all request will be affected
- name: TOXICITY
value: "100"
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
Network interface
It defines the network interface to be used for the proxy. It can be tuned via NETWORK_INTERFACE
environment variable.
Use the following example to tune this:
## provide the port for proxy server
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# provide the network interface for proxy
- name: NETWORK_INTERFACE
value: "eth0"
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
# map of headers to modify/add
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'
Container runtime and socket path
It defines the CONTAINER_RUNTIME
and SOCKET_PATH
environment variables to set the container runtime and socket file path, respectively.
CONTAINER_RUNTIME
: It supportsdocker
,containerd
, andcrio
runtimes. The default value isdocker
.SOCKET_PATH
: It contains path of docker socket file by default(/var/run/docker.sock
). Forcontainerd
, specify path as/var/containerd/containerd.sock
. Forcrio
, speecify path as/var/run/crio/crio.sock
.
Use the following example to tune it:
## provide the container runtime and socket file path
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: engine-nginx
spec:
engineState: "active"
annotationCheck: "false"
appinfo:
appns: "default"
applabel: "app=nginx"
appkind: "deployment"
chaosServiceAccount: litmus-admin
experiments:
- name: pod-http-chaos
spec:
components:
env:
# runtime for the container
# supports docker, containerd, crio
- name: CONTAINER_RUNTIME
value: "docker"
# path of the socket file
- name: SOCKET_PATH
value: "/var/run/docker.sock"
# provide the port of the targeted service
- name: TARGET_SERVICE_PORT
value: "80"
# map of headers to modify/add
- name: HEADERS_MAP
value: '{"X-Litmus-Test-Header": "X-Litmus-Test-Value"}'