> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/chaos-testing/actions/container-action.md).

# Container Action

### What is a Container Action? <a href="#what-is-a-container-action" id="what-is-a-container-action"></a>

A **Container Action** allows you to execute commands inside a container during chaos experiment execution. This provides powerful capabilities to:

* Execute custom commands in containerized environments
* Perform application-specific operations during experiments
* Run validation or diagnostic commands
* Interact with containerized applications and services
* Implement custom setup or cleanup operations
* Execute scripts or binaries available in container images

### When to Use Container Actions <a href="#when-to-use-container-actions" id="when-to-use-container-actions"></a>

Container Actions are particularly valuable in the following scenarios:

#### Application Validation <a href="#application-validation" id="application-validation"></a>

* **Health Checks**: Execute application-specific health check commands
* **State Verification**: Validate application state during chaos events
* **Data Validation**: Check data consistency within containers
* **Process Monitoring**: Verify that critical processes are running

#### System Operations <a href="#system-operations" id="system-operations"></a>

* **Configuration Changes**: Apply configuration changes during experiments
* **Service Restarts**: Restart services or processes within containers
* **Cache Operations**: Clear caches or perform cache-related operations
* **Log Collection**: Gather application logs for analysis

#### Environment Setup/Cleanup <a href="#environment-setupcleanup" id="environment-setupcleanup"></a>

* **Pre-experiment Setup**: Prepare the containerized environment before chaos
* **Post-experiment Cleanup**: Clean up resources after experiment completion
* **Test Data Management**: Set up or tear down test data
* **State Preparation**: Configure specific application states

#### Diagnostic Operations <a href="#diagnostic-operations" id="diagnostic-operations"></a>

* **Network Diagnostics**: Run network connectivity tests from within containers
* **Resource Checks**: Monitor resource usage from inside containers
* **Dependency Validation**: Verify connectivity to dependent services
* **Performance Metrics**: Collect application-specific performance data

### How to configure a Container Action <a href="#how-to-configure-a-container-action" id="how-to-configure-a-container-action"></a>

#### Step 1: Create a New Action <a href="#step-1-create-a-new-action" id="step-1-create-a-new-action"></a>

1. Navigate to your **Probes & Actions** and go to the **Actions** tab
2. Click **New Action** and select **Container** from the dropdown

![create container action](/files/0iNjbDeV04mFzUKFhNdz)

#### Step 2: Configure Metadata <a href="#step-2-configure-metadata" id="step-2-configure-metadata"></a>

Configure the following parameters for your container action:

* **Name**: Provide a descriptive name for the container action
* **Description** (optional): Add a description to explain the action's purpose
* **Tags** (optional): Add tags for better organization and filtering
* **Infrastructure Type**: Select the target infrastructure (Kubernetes)

![configure container action](/files/VzO8LfhSqQqp8Y20LZA7)

#### Step 3: Configure Action Properties <a href="#step-3-configure-action-properties" id="step-3-configure-action-properties"></a>

In the Action Properties section, configure the container and command details:

* **Container Image**: Specify the container image to use (e.g., `bitnami/kubectl:latest`, `busybox:latest`, `alpine:latest`)
* **Command**: Specify the command to execute inside the container as an array (e.g., `/bin/sh`, `-c`)
  * You can add multiple command arguments by clicking the **+ Add** button
* **Arguments**: Provide the actual command or script to execute (e.g., `echo "Hello World"`)
* **Environment Variables** (optional): Add environment variables as key-value pairs
  * Click **+ Add** to add new environment variables
* **Namespace**: Specify the Kubernetes namespace (default: `default`)
* **Image Pull Policy**: Define when to pull the image (`IfNotPresent`, `Always`, `Never`)

![container action properties](/files/31A4Daka3jIW3n1PdRnZ)

#### Step 4: Configure Advanced Settings (Optional) <a href="#step-4-configure-advanced-settings-optional" id="step-4-configure-advanced-settings-optional"></a>

Configure advanced settings as needed:

**Advanced Configuration**

* **Service Account Name**: Kubernetes service account to use
* **Image Pull Secrets**: Secrets for private registries
* **Labels** and **Annotations**: Custom metadata for the action container
* **Node Selector**: Node selection constraints
* **Tolerations**: Allow scheduling on nodes with matching taints
* **Node Affinity**: Required or preferred node affinity rules
* **Resource Limits**: Set memory and CPU limits (e.g., `512Mi`, `500m`)
* **Resource Requests**: Set memory and CPU requests (e.g., `256Mi`, `100m`)

**Volumes**

* Add volumes to mount into the action container with volume name, mount path, and volume source

**Volume Mounts**

* Specify additional volume mounts with name, mount path, and optional sub path

**Security Configuration**

* **Host Network**, **HostPID**, **Host IPC**: Use host namespaces
* **Allow Privilege Escalation**: Allow gaining more privileges
* **Read Only Root Filesystem**: Mount root filesystem as read-only
* **Privileged**: Run in privileged mode
* **Run As Non Root**: Ensure non-root execution
* **Run as user** and **Run as group**: Specify user and group IDs
* **FS Group**: Filesystem group ID for volume ownership

#### Step 5: Configure Run Properties <a href="#step-5-configure-run-properties" id="step-5-configure-run-properties"></a>

Configure the execution behavior:

* **Timeout**: Maximum time for action execution (e.g., `10s`)
* **Interval**: Time between successive executions (e.g., `2s`)
* **Max Retries**: Number of retry attempts (e.g., `1`)
* **Initial Delay**: Delay before first execution (e.g., `5s`)

![container action run properties](/files/ChsPUhZowJzNnxJLQ1DA)

#### Step 6: Position the Action <a href="#step-6-position-the-action" id="step-6-position-the-action"></a>

Place the container action at the appropriate point in your experiment workflow:

* **Pre-experiment**: Setup or validation before chaos injection
* **Mid-experiment**: Operations or validation during chaos
* **Post-experiment**: Cleanup or final validation after chaos
* **Between Phases**: Transition logic between different experiment phases

### Next Steps <a href="#next-steps" id="next-steps"></a>

* [Learn about Delay Actions](/resilience-testing/chaos-testing/actions/delay-action.md)
* [Learn about Custom Script Actions](/resilience-testing/chaos-testing/actions/custom-script-action.md)
* Explore experiment timeline view (see Experiments documentation)
* [Create experiments with actions](/resilience-testing/chaos-testing/experiments.md)
