ECS Fargate memory hog
The ECS Fargate memory Hog experiment enables you to intentionally increase the memory usage of an ECS task container for a defined period, allowing you to assess and test the container's performance under high memory utilization conditions or latency caused due to it. This experiment primarily involves ECS Fargate and doesn’t depend on EC2 instances. They focus on altering the state or resources of ECS containers without direct container interaction.
Use cases
ECS Fargate memory hog:
- Tests the behavior of your ECS tasks subjected to memory stress, and validates the resilience and performance of your ECS tasks during the stress.
- Employes a sidecar container to augment the memory utilization of an ECS task, which may result in latency issues impacting the performance of the main container.
- Validates the behavior of your application and infrastructure during a heavy memory load, such as:
- Testing the resilience of your system during stress, including verifying if the latency of the main container is increased and if the container fail to survive.
Prerequisites
- Kubernetes >= 1.17
- ECS cluster running with the desired tasks and containers and familiarity with ECS service update and deployment concepts.
- Create a Kubernetes secret that has the AWS access configuration(key) in the
CHAOS_NAMESPACE
. Below is a sample secret file:
apiVersion: v1
kind: Secret
metadata:
name: cloud-secret
type: Opaque
stringData:
cloud_config.yml: |-
# Add the cloud AWS credentials respectively
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXX
HCE recommends that you use the same secret name, that is, cloud-secret
. Otherwise, you will need to update the AWS_SHARED_CREDENTIALS_FILE
environment variable in the fault template with the new secret name and you won't be able to use the default health check probes.
Below is an example AWS policy to execute the fault.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecs:DescribeTasks",
"ecs:DescribeServices",
"ecs:DescribeTaskDefinition",
"ecs:RegisterTaskDefinition",
"ecs:UpdateService",
"ecs:ListTasks",
"ecs:DeregisterTaskDefinition"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"iam:PassRole"
],
"Resource": "*"
}
]
}
- Refer to AWS named profile for chaos for how to use a different profile for AWS faults.
- The ECS containers should be in a healthy state before and after introducing chaos. Refer to the common attributes and AWS-specific tunables to tune the common tunables for all faults and AWS-specific tunables.
- Refer to the superset permission/policy to execute all AWS faults.
Mandatory tunables
Tunable | Description | Notes |
---|---|---|
CLUSTER_NAME | Name of the target ECS cluster | For example, cluster-1 . |
SERVICE_NAME | Name of the ECS service under chaos | For example, nginx-svc . |
REGION | Region name of the target ECS cluster | For example, us-east-1 . |
Optional tunables
Tunable | Description | Notes |
---|---|---|
TOTAL_CHAOS_DURATION | Duration that you specify, through which chaos is injected into the target resource (in seconds) | Default: 30s. For more information, go to duration of the chaos. |
CHAOS_INTERVAL | Interval between successive instance terminations (in seconds) | Default: 30s. For more information, go to chaos interval. |
AWS_SHARED_CREDENTIALS_FILE | Path to the AWS secret credentials | Defaults to /tmp/cloud_config.yml . |
MEMORY_IN_MEGABYTE | Provide the memory in Megabytes to stress the ECS task. | Default: 500. For more information, go to memory consumed in MB. |
CONTAINER_IMAGE | Provide stress image for the sidecar container. | Default: nginx. For more information, go to stress container image. |
RAMP_TIME | Period to wait before and after injecting chaos (in seconds) | For example, 30 s. For more information, go to ramp time. |
Memory consumed in megabytes
ECS Fargate memory stress with a specified memory in Megabytes. Tune it by using the MEMORY_IN_MEGABYTE
environment variable.
The following YAML snippet illustrates the use of this environment variable:
# Set container image for the target ECS task
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: aws-nginx
spec:
engineState: "active"
annotationCheck: "false"
chaosServiceAccount: litmus-admin
experiments:
- name: ecs-fargate-memory-hog
spec:
components:
env:
- name: MEMORY_IN_MEGABYTE
value: '500'
- name: REGION
value: 'us-east-2'
- name: TOTAL_CHAOS_DURATION
VALUE: '60'
Stress container image
ECS Fargate memory hog chaos with custom stress container image for sidecar container to inject chaos. Tune it by using the CONTAINER_IMAGE
environment variable.
The following YAML snippet illustrates the use of this environment variable:
# Set container image for the target ECS task
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: aws-nginx
spec:
engineState: "active"
annotationCheck: "false"
chaosServiceAccount: litmus-admin
experiments:
- name: ecs-fargate-memory-hog
spec:
components:
env:
- name: CONTAINER_IMAGE
value: 'chaosnative/go-runner:ci'
- name: MEMORY_IN_MEGABYTE
value: '500'
- name: REGION
value: 'us-east-2'
- name: TOTAL_CHAOS_DURATION
VALUE: '60'