Skip to main content

A client to create experiments in ChaosMesh

Project description

Chaos Mesh Client

Introduction

Chaos Mesh is an open source cloud-native Chaos Engineering platform that allows you to simulate various faults and orchestrate fault scenarios in your kubernetes cluster. This client is written in Python and provides a single point of entry to create and manage experiments in Chaos Mesh.

Getting Started

To start using Chaos Mesh, please follow the installation steps in the documentation.

To create a Chaos Mesh client, you can use the following code:

from chaosmesh.client import Client, Experiment
from chaosmesh.k8s.selector import Selector

# creating the ChaosMesh client
client = Client(version="v1alpha1")

# target pods selector; by labelSector or by pods in specified namespaces
selector = Selector(labelSelectors={"app": "filebeat"}, pods=None, namespaces=None)

Experiment Types

Chaos Mesh supports various types of experiments, including Pod faults, stress tests, JVM faults, and Host faults.

Pod Faults

  • Pod failure
  • Pod kill
  • Container kill

Stress Tests

  • CPU
  • Memory

JVM Faults

  • GC
  • Exception

Host Faults

  • CPU
  • Memory

Experiment Examples

Here are some examples of how you can create experiments in Chaos Mesh:

Pod Failure Experiment

# name of the experiment
exp_name = str(uuid.uuid4())

# starting up the pod failure experiment
client.start_experiment(Experiment.POD_FAILURE, namespace="default", name=exp_name, selector=selector)

Pod Kill Experiment

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.POD_KILL, namespace="default", name=exp_name, selector=selector)

Container Kill Experiment

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.CONTAINER_KILL, namespace="default", name=exp_name, selector=selector, container_names=['main'])

CPU Stress Test Experiment

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.POD_STRESS_CPU, namespace="default", name=exp_name, selector=selector, container_names=['main'])

Memory Stress Test Experiment

exp_name = str(uuid.uuid4())

# starting up the pod kill experiment
client.start_experiment(Experiment.POD_STRESS_MEMORY, namespace="default", name=exp_name, selector=selector, container_names=['main'])

GC Experiment

# name of the experiment
exp_name = str(uuid.uuid4())

client.start_experiment(Experiment.GC, namespace="default", name=exp_name, selector=selector, port=8080)

Exception Experiment

exp_name = str(uuid.uuid4())

client.start_experiment(Experiment.RAISE_EXCEPTION, namespace="default",
                        name=exp_name, selector=select

Host CPU stress

exp_name = str(uuid.uuid4())

# starting up the host cpu stress experiment
client.start_experiment(Experiment.HOST_STRESS_CPU, namespace="default", name=exp_name,
                        address=["10.225.66.224", "10.225.67.213", "10.225.66.231", "10.225.66.138", "10.225.66.192", "10.225.67.52", "10.225.67.103"],
                        load=1000)

Host Memory stress

exp_name = str(uuid.uuid4())

# starting up the host memory stress experiment
client.start_experiment(Experiment.HOST_STRESS_MEMORY, namespace="default", name=exp_name,
                        address=["10.225.66.224", "10.225.67.213", "10.225.66.231", "10.225.66.138", "10.225.66.192", "10.225.67.52", "10.225.67.103"],
                        size="30GB")

Pause an experiment

In order to pause an experiment you can use the following command

# pausing the experiment
client.pause_experiment(Experiment.POD_STRESS_MEMORY, namespace="default", name=exp_name)

Delete the experiment

The experiment can be removed from the k8s cluster using the following command

client.delete_experiment(Experiment.POD_STRESS_MEMORY, namespace="default", name=exp_name)

Logging

Initializing the ChaosMesh logger

import logging, sys

logging.getLogger("chaosmesh")
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chaos_mesh-1.2.5.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

chaos_mesh-1.2.5-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file chaos_mesh-1.2.5.tar.gz.

File metadata

  • Download URL: chaos_mesh-1.2.5.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for chaos_mesh-1.2.5.tar.gz
Algorithm Hash digest
SHA256 ec6886482ed1d74db3677a4378c7df92dfd8828ddb700d06bf45314c01b29cc4
MD5 49adfd5353d91f3d816da0c193f04780
BLAKE2b-256 685532d8d40e2bfe2d1489138bd760edf1d5349d70e3d30c6ab6a4fcc76a2295

See more details on using hashes here.

File details

Details for the file chaos_mesh-1.2.5-py3-none-any.whl.

File metadata

  • Download URL: chaos_mesh-1.2.5-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.5

File hashes

Hashes for chaos_mesh-1.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ac49925460e4513b91ebddd7686b85ed62201be582a47a56302bcd94548b57
MD5 bfad937d0fecfe7beaa6084bae71660e
BLAKE2b-256 187e7956fe51fd42bace21db5f6ead4aea03f637c71445eb633fb95e5ea6f9aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page