Skip to main content

Container kill

Container kill is a Kubernetes pod-level chaos fault that causes container failure on specific (or random) replicas of an application resource.

  • It tests an application's deployment sanity (replica availability and uninterrupted service) and recovery workflow.
  • It tests the recovery of pods that possess sidecar containers.

Container Kill

Usage

View fault usage
It tests an application's deployment sanity (replica availability and uninterrupted service) and recovery workflow when certain replicas are not available.

Prerequisites

  • Kubernetes > 1.16.

Default validations

The application pods should be in running state before and after chaos injection.

Fault tunables

Fault tunables

Optional fields

Variables Description Notes
TARGET_CONTAINER Name of the container that is killed inside the pod. If it is not provided, the fault deletes first container.
CHAOS_INTERVAL Time interval between two successive container kills (in seconds). Defaults to 10s.
TOTAL_CHAOS_DURATION Duration that you specify, through which chaos is injected into the target resource (in seconds). Defaults to 20s.
PODS_AFFECTED_PERC Percentage of total pods to target, takes numeric values only. Defaults to 0 (corresponds to 1 replica).
TARGET_PODS Comma-separated list of application pod name subject to container kill. If it is not provided, target pods are randomly based on appLabels provided.
LIB_IMAGE Image used to kill the container. Defaults to litmuschaos/go-runner:latest.
RAMP_TIME Period to wait before injecting chaos (in seconds). For example, 30s.
SEQUENCE It defines sequence of chaos execution for multiple target pods Default value: parallel. Supported: serial, parallel
SIGNAL It contains termination signal used for container kill Defaults to SIGKILL.
SOCKET_PATH Path to the containerd/crio/docker socket file. Defaults to /var/run/docker.sock.
CONTAINER_RUNTIME Container runtime interface for the cluster. Defaults to docker. Supported docker, containerd and crio.

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.

Kill specific container

It defines the name of the target container which is subject to chaos. You can tune it using TARGET_CONTAINER environment variable. If TARGET_CONTAINER environment variable is set to empty, the fault uses the first container of the target pod.

# kill the specific target container
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: container-kill
spec:
components:
env:
# name of the target container
- name: TARGET_CONTAINER
value: "nginx"
- name: TOTAL_CHAOS_DURATION
VALUE: "60"

Container runtime and socket path

It defines the CONTAINER_RUNTIME and SOCKET_PATH environment variable that help set the container runtime and socket file path, respectively.

  • CONTAINER_RUNTIME: It supports docker, containerd, and crio runtimes. The default value is docker.
  • SOCKET_PATH: It contains the path of the docker socket file by default(/var/run/docker.sock). For containerd, specify path as /var/containerd/containerd.sock. For crio, speecify path as /var/run/crio/crio.sock.
## 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: container-kill
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"
- name: TOTAL_CHAOS_DURATION
VALUE: "60"

Signal for kill

It defines the Linux signal passed while killing the container. You can tune it using the SIGNAL environment variable. Its default value is set to SIGTERM.

# specific linux signal passed while kiiling container
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: container-kill
spec:
components:
env:
# signal passed while killing container
# defaults to SIGTERM
- name: SIGNAL
value: "SIGKILL"
- name: TOTAL_CHAOS_DURATION
VALUE: "60"