Skip to content

Extension chaosk8s

Version 0.25.0
Repository https://github.com/chaostoolkit/chaostoolkit-kubernetes

Build Status codecov Python versions Downloads

This project contains activities, such as probes and actions, you can call from your experiment through the Chaos Toolkit to perform Chaos Engineering against the Kubernetes API: killing a pod, removing a statefulset or node…

Install

To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.

$ pip install chaostoolkit-kubernetes

Usage

To use the probes and actions from this package, add the following to your experiment file:

{
    "title": "Do we remain available in face of pod going down?",
    "description": "We expect Kubernetes to handle the situation gracefully when a pod goes down",
    "tags": ["kubernetes"],
    "steady-state-hypothesis": {
        "title": "Verifying service remains healthy",
        "probes": [
            {
                "name": "all-our-microservices-should-be-healthy",
                "type": "probe",
                "tolerance": true,
                "provider": {
                    "type": "python",
                    "module": "chaosk8s.probes",
                    "func": "microservice_available_and_healthy",
                    "arguments": {
                        "name": "myapp"
                    }
                }
            }
        ]
    },
    "method": [
        {
            "type": "action",
            "name": "terminate-db-pod",
            "provider": {
                "type": "python",
                "module": "chaosk8s.pod.actions",
                "func": "terminate_pods",
                "arguments": {
                    "label_selector": "app=my-app",
                    "name_pattern": "my-app-[0-9]$",
                    "rand": true
                }
            },
            "pauses": {
                "after": 5
            }
        }
    ]
}

That’s it! Notice how the action gives you the way to kill one pod randomly.

Please explore the documentation to see existing probes and actions.

Configuration

Use ~/.kube/config

If you have a valid entry in your ~/.kube/config file for the cluster you want to target, then there is nothing to be done.

You may specify KUBECONFIG to specify a different location.

$ export KUBECONFIG=/tmp/my-config

Specify the Kubernetes context

Quite often, your Kubernetes configuration contains several entries and you need to define the one to use as a default context when not it isn’t explicitely provided.

You may of course change your default using kubectl config use-context KUBERNETES_CONTEXT but you can also be explicit in your experiment as follows:

{
    "title": "Do we remain available in face of pod going down?",
    "description": "We expect Kubernetes to handle the situation gracefully when a pod goes down",
    "tags": ["kubernetes"],
    "secrets": {
        "k8s": {
            "KUBERNETES_CONTEXT": "..."
        }
    },
    "steady-state-hypothesis": {
        "title": "Verifying service remains healthy",
        "probes": [
            {
                "name": "all-our-microservices-should-be-healthy",
                "type": "probe",
                "tolerance": true,
                "secrets": ["k8s"],
                "provider": {
                    "type": "python",
                    "module": "chaosk8s.probes",
                    "func": "microservice_available_and_healthy",
                    "arguments": {
                        "name": "myapp"
                    }
                }
            }
        ]
    },
    "method": [
        {
            "type": "action",
            "name": "terminate-db-pod",
            "secrets": ["k8s"],
            "provider": {
                "type": "python",
                "module": "chaosk8s.pod.actions",
                "func": "terminate_pods",
                "arguments": {
                    "label_selector": "app=my-app",
                    "name_pattern": "my-app-[0-9]$",
                    "rand": true
                }
            },
            "pauses": {
                "after": 5
            }
        }
    ]
}

You need to specify the KUBERNETES_CONTEXT secret key to the name of the context you want the experiment to use. Make sure to also inform the actions and probes about the secret entries they should be passed "secrets": ["k8s"].

Use a Pod’s service account

When running from a pod (not your local machine or a CI for instance), the ./.kube/config file does not exist. Instead, the credentials can be found at /var/run/secrets/kubernetes.io/serviceaccount/token.

To let the extension know about this, simply set CHAOSTOOLKIT_IN_POD from the environment variable of the pod specification:

env:
- name: CHAOSTOOLKIT_IN_POD
  value: "true"

Pass all credentials in the experiment

Finally, you may pass explicitely all required credentials information to the experiment as follows:

Using an API key

{
    "secrets": {
        "kubernetes": {
            "KUBERNETES_HOST": "http://somehost",
            "KUBERNETES_API_KEY": {
                "type": "env",
                "key": "SOME_ENV_VAR"
            }
        }
    }
}

Using a username/password

{
    "secrets": {
        "kubernetes": {
            "KUBERNETES_HOST": "http://somehost",
            "KUBERNETES_USERNAME": {
                "type": "env",
                "key": "SOME_ENV_VAR"
            },
            "KUBERNETES_PASSWORD": {
                "type": "env",
                "key": "SOME_ENV_VAR"
            }
        }
    }
}

Using a TLS key/certificate

{
    "secrets": {
        "kubernetes": {
            "KUBERNETES_HOST": "http://somehost",
            "KUBERNETES_CERT_FILE": {
                "type": "env",
                "key": "SOME_ENV_VAR"
            },
            "KUBERNETES_KEY_FILE": {
                "type": "env",
                "key": "SOME_ENV_VAR"
            }
        }
    }
}

Managed Kubernetes Clusters Authentication

On some managed Kubernetes clusters, you also need to authenticate against the platform itself because the Kubernetes authentication is delegated to it.

Google Cloud Platform

In addition to your Kubernetes credentials (via the ~/.kube/config file), you need to authenticate against the Google Cloud Platform itself. Usually this is done via:

$ gcloud auth login

But can also be achieved by defining the GOOGLE_APPLICATION_CREDENTIALS environment variable.

Contribute

If you wish to contribute more functions to this package, you are more than welcome to do so. Please fork this project, make your changes following the usual PEP 8 code style, add appropriate tests and submit a PR for review.

The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.

Develop

If you wish to develop on this project, make sure to install the development dependencies. But first, create a virtual environment and then install those dependencies.

$ pip install -r requirements-dev.txt -r requirements.txt

Then, point your environment to this directory:

$ pip install -e .

Now, you can edit the files and they will be automatically be seen by your environment, even when running from the chaos command locally.

Test

To run the tests for the project execute the following:

$ pytest

Exported Activities

actions


kill_microservice

Type action
Module chaosk8s.actions
Name kill_microservice
Return None

!!!DEPRECATED!!!

Signature:

def kill_microservice(name: str,
                      ns: str = 'default',
                      label_selector: str = 'name in ({name})',
                      secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.actions",
    "func": "kill_microservice",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "kill-microservice",
  "type": "action"
}
name: kill-microservice
provider:
  arguments:
    name: ''
  func: kill_microservice
  module: chaosk8s.actions
  type: python
type: action

remove_service_endpoint

Type action
Module chaosk8s.actions
Name remove_service_endpoint
Return None

!!!DEPRECATED!!!

Signature:

def remove_service_endpoint(name: str,
                            ns: str = 'default',
                            secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.actions",
    "func": "remove_service_endpoint",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "remove-service-endpoint",
  "type": "action"
}
name: remove-service-endpoint
provider:
  arguments:
    name: ''
  func: remove_service_endpoint
  module: chaosk8s.actions
  type: python
type: action

scale_microservice

Type action
Module chaosk8s.actions
Name scale_microservice
Return None

!!!DEPRECATED!!!

Signature:

def scale_microservice(name: str,
                       replicas: int,
                       ns: str = 'default',
                       secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
replicas integer Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.actions",
    "func": "scale_microservice",
    "arguments": {
      "replicas": 0,
      "name": ""
    },
    "type": "python"
  },
  "name": "scale-microservice",
  "type": "action"
}
name: scale-microservice
provider:
  arguments:
    name: ''
    replicas: 0
  func: scale_microservice
  module: chaosk8s.actions
  type: python
type: action

start_microservice

Type action
Module chaosk8s.actions
Name start_microservice
Return None

!!!DEPRECATED!!!

Signature:

def start_microservice(spec_path: str,
                       ns: str = 'default',
                       secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
spec_path string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.actions",
    "func": "start_microservice",
    "arguments": {
      "spec_path": ""
    },
    "type": "python"
  },
  "name": "start-microservice",
  "type": "action"
}
name: start-microservice
provider:
  arguments:
    spec_path: ''
  func: start_microservice
  module: chaosk8s.actions
  type: python
type: action

networking


allow_dns_access

Type action
Module chaosk8s.networking.actions
Name allow_dns_access
Return None

Convenient helper rule to DNS access from all pods in a namespace, unless `label_selectors, in which case, only matching pods will be impacted.

Signature:

def allow_dns_access(label_selectors: Dict[str, Any] = None,
                     ns: str = 'default',
                     secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
label_selectors mapping null No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "allow_dns_access",
    "type": "python"
  },
  "name": "allow-dns-access",
  "type": "action"
}
name: allow-dns-access
provider:
  func: allow_dns_access
  module: chaosk8s.networking.actions
  type: python
type: action

create_network_policy

Type action
Module chaosk8s.networking.actions
Name create_network_policy
Return None

Create a network policy in the given namespace eitehr from the definition as spec or from a file containing the definition at spec_path.

Signature:

def create_network_policy(spec: Dict[str, Any] = None,
                          spec_path: str = None,
                          ns: str = 'default',
                          secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
spec mapping null No
spec_path string null No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "create_network_policy",
    "type": "python"
  },
  "name": "create-network-policy",
  "type": "action"
}
name: create-network-policy
provider:
  func: create_network_policy
  module: chaosk8s.networking.actions
  type: python
type: action

deny_all_egress

Type action
Module chaosk8s.networking.actions
Name deny_all_egress
Return None

Convenient helper rule to deny all egress network from all pods in a namespace, unless `label_selectors, in which case, only matching pods will be impacted.

Signature:

def deny_all_egress(label_selectors: Dict[str, Any] = None,
                    ns: str = 'default',
                    secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
label_selectors mapping null No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "deny_all_egress",
    "type": "python"
  },
  "name": "deny-all-egress",
  "type": "action"
}
name: deny-all-egress
provider:
  func: deny_all_egress
  module: chaosk8s.networking.actions
  type: python
type: action

deny_all_ingress

Type action
Module chaosk8s.networking.actions
Name deny_all_ingress
Return None

Convenient helper policy to deny ingress network to all pods in a namespace, unless `label_selectors, in which case, only matching pods will be impacted.

Signature:

def deny_all_ingress(label_selectors: Dict[str, Any] = None,
                     ns: str = 'default',
                     secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
label_selectors mapping null No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "deny_all_ingress",
    "type": "python"
  },
  "name": "deny-all-ingress",
  "type": "action"
}
name: deny-all-ingress
provider:
  func: deny_all_ingress
  module: chaosk8s.networking.actions
  type: python
type: action

remove_allow_dns_access

Type action
Module chaosk8s.networking.actions
Name remove_allow_dns_access
Return None

Remove the rule set by the allow_dns_access action.

Signature:

def remove_allow_dns_access(ns: str = 'default',
                            secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "remove_allow_dns_access",
    "type": "python"
  },
  "name": "remove-allow-dns-access",
  "type": "action"
}
name: remove-allow-dns-access
provider:
  func: remove_allow_dns_access
  module: chaosk8s.networking.actions
  type: python
type: action

remove_deny_all_egress

Type action
Module chaosk8s.networking.actions
Name remove_deny_all_egress
Return None

Remove the rule set by the deny_all_egress action.

Signature:

def remove_deny_all_egress(ns: str = 'default',
                           secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "remove_deny_all_egress",
    "type": "python"
  },
  "name": "remove-deny-all-egress",
  "type": "action"
}
name: remove-deny-all-egress
provider:
  func: remove_deny_all_egress
  module: chaosk8s.networking.actions
  type: python
type: action

remove_deny_all_ingress

Type action
Module chaosk8s.networking.actions
Name remove_deny_all_ingress
Return None

Remove the rule set by the deny_all_ingress action.

Signature:

def remove_deny_all_ingress(ns: str = 'default',
                            secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "remove_deny_all_ingress",
    "type": "python"
  },
  "name": "remove-deny-all-ingress",
  "type": "action"
}
name: remove-deny-all-ingress
provider:
  func: remove_deny_all_ingress
  module: chaosk8s.networking.actions
  type: python
type: action

remove_network_policy

Type action
Module chaosk8s.networking.actions
Name remove_network_policy
Return None

Create a network policy in the given namespace eitehr from the definition as spec or from a file containing the definition at spec_path.

Signature:

def remove_network_policy(name: str,
                          ns: str = 'default',
                          secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.networking.actions",
    "func": "remove_network_policy",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "remove-network-policy",
  "type": "action"
}
name: remove-network-policy
provider:
  arguments:
    name: ''
  func: remove_network_policy
  module: chaosk8s.networking.actions
  type: python
type: action

crd


create_cluster_custom_object

Type action
Module chaosk8s.crd.actions
Name create_cluster_custom_object
Return mapping

Delete a custom object in the given namespace.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def create_cluster_custom_object(
        group: str,
        version: str,
        plural: str,
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "create_cluster_custom_object",
    "arguments": {
      "group": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "create-cluster-custom-object",
  "type": "action"
}
name: create-cluster-custom-object
provider:
  arguments:
    group: ''
    plural: ''
    version: ''
  func: create_cluster_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

create_custom_object

Type action
Module chaosk8s.crd.actions
Name create_custom_object
Return mapping

Create a custom object in the given namespace. Its custom resource definition must already exists or this will fail with a 404.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def create_custom_object(
        group: str,
        version: str,
        plural: str,
        ns: str = 'default',
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
ns string “default” No
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "create_custom_object",
    "arguments": {
      "group": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "create-custom-object",
  "type": "action"
}
name: create-custom-object
provider:
  arguments:
    group: ''
    plural: ''
    version: ''
  func: create_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

delete_cluster_custom_object

Type action
Module chaosk8s.crd.actions
Name delete_cluster_custom_object
Return mapping

Delete a custom object cluster wide.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def delete_cluster_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "delete_cluster_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "delete-cluster-custom-object",
  "type": "action"
}
name: delete-cluster-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: delete_cluster_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

delete_custom_object

Type action
Module chaosk8s.crd.actions
Name delete_custom_object
Return mapping

Create a custom object cluster wide. Its custom resource definition must already exists or this will fail with a 404.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def delete_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        ns: str = 'default',
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "delete_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "delete-custom-object",
  "type": "action"
}
name: delete-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: delete_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

get_cluster_custom_object

Type probe
Module chaosk8s.crd.probes
Name get_cluster_custom_object
Return mapping

Get a custom object cluster-wide.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def get_cluster_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.probes",
    "func": "get_cluster_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "get-cluster-custom-object",
  "type": "probe"
}
name: get-cluster-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: get_cluster_custom_object
  module: chaosk8s.crd.probes
  type: python
type: probe

get_custom_object

Type probe
Module chaosk8s.crd.probes
Name get_custom_object
Return mapping

Get a custom object in the given namespace.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def get_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        ns: str = 'default',
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.probes",
    "func": "get_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "get-custom-object",
  "type": "probe"
}
name: get-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: get_custom_object
  module: chaosk8s.crd.probes
  type: python
type: probe

list_cluster_custom_objects

Type probe
Module chaosk8s.crd.probes
Name list_cluster_custom_objects
Return list

List custom objects cluster-wide.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def list_cluster_custom_objects(
        group: str,
        version: str,
        plural: str,
        secrets: Dict[str, Dict[str, str]] = None) -> List[Dict[str, Any]]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.probes",
    "func": "list_cluster_custom_objects",
    "arguments": {
      "group": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "list-cluster-custom-objects",
  "type": "probe"
}
name: list-cluster-custom-objects
provider:
  arguments:
    group: ''
    plural: ''
    version: ''
  func: list_cluster_custom_objects
  module: chaosk8s.crd.probes
  type: python
type: probe

list_custom_objects

Type probe
Module chaosk8s.crd.probes
Name list_custom_objects
Return list

List custom objects in the given namespace.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def list_custom_objects(
        group: str,
        version: str,
        plural: str,
        ns: str = 'default',
        secrets: Dict[str, Dict[str, str]] = None) -> List[Dict[str, Any]]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.probes",
    "func": "list_custom_objects",
    "arguments": {
      "group": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "list-custom-objects",
  "type": "probe"
}
name: list-custom-objects
provider:
  arguments:
    group: ''
    plural: ''
    version: ''
  func: list_custom_objects
  module: chaosk8s.crd.probes
  type: python
type: probe

patch_cluster_custom_object

Type action
Module chaosk8s.crd.actions
Name patch_cluster_custom_object
Return mapping

Patch a custom object cluster-wide. The resource must be the updated version to apply. Force will re-acquire conflicting fields owned by others.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def patch_cluster_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        force: bool = False,
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
force boolean false No
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "patch_cluster_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "patch-cluster-custom-object",
  "type": "action"
}
name: patch-cluster-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: patch_cluster_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

patch_custom_object

Type action
Module chaosk8s.crd.actions
Name patch_custom_object
Return mapping

Patch a custom object in the given namespace. The resource must be the updated version to apply. Force will re-acquire conflicting fields owned by others.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def patch_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        ns: str = 'default',
        force: bool = False,
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
ns string “default” No
force boolean false No
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "patch_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "patch-custom-object",
  "type": "action"
}
name: patch-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: patch_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

replace_cluster_custom_object

Type action
Module chaosk8s.crd.actions
Name replace_cluster_custom_object
Return mapping

Replace a custom object in the given namespace. The resource must be the new version to apply.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def replace_cluster_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        force: bool = False,
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
force boolean false No
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "replace_cluster_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "replace-cluster-custom-object",
  "type": "action"
}
name: replace-cluster-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: replace_cluster_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

replace_custom_object

Type action
Module chaosk8s.crd.actions
Name replace_custom_object
Return mapping

Replace a custom object in the given namespace. The resource must be the new version to apply.

Read more about custom resources here: https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/

Signature:

def replace_custom_object(
        group: str,
        version: str,
        plural: str,
        name: str,
        ns: str = 'default',
        force: bool = False,
        resource: Dict[str, Any] = None,
        resource_as_yaml_file: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, Any]:
    pass

Arguments:

Name Type Default Required
group string Yes
version string Yes
plural string Yes
name string Yes
ns string “default” No
force boolean false No
resource mapping null No
resource_as_yaml_file string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.crd.actions",
    "func": "replace_custom_object",
    "arguments": {
      "group": "",
      "name": "",
      "version": "",
      "plural": ""
    },
    "type": "python"
  },
  "name": "replace-custom-object",
  "type": "action"
}
name: replace-custom-object
provider:
  arguments:
    group: ''
    name: ''
    plural: ''
    version: ''
  func: replace_custom_object
  module: chaosk8s.crd.actions
  type: python
type: action

statefulset


create_statefulset

Type action
Module chaosk8s.statefulset.actions
Name create_statefulset
Return None

Create a statefulset described by the service config, which must be the path to the JSON or YAML representation of the statefulset.

Signature:

def create_statefulset(spec_path: str,
                       ns: str = 'default',
                       secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
spec_path string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.statefulset.actions",
    "func": "create_statefulset",
    "arguments": {
      "spec_path": ""
    },
    "type": "python"
  },
  "name": "create-statefulset",
  "type": "action"
}
name: create-statefulset
provider:
  arguments:
    spec_path: ''
  func: create_statefulset
  module: chaosk8s.statefulset.actions
  type: python
type: action

remove_statefulset

Type action
Module chaosk8s.statefulset.actions
Name remove_statefulset
Return None

Remove a statefulset by name in the namespace ns.

The statefulset is removed by deleting it without a graceful period to trigger an abrupt termination.

The selected resources are matched by the given label_selector.

Signature:

def remove_statefulset(name: str = None,
                       ns: str = 'default',
                       label_selector: str = None,
                       secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string null No
ns string “default” No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.statefulset.actions",
    "func": "remove_statefulset",
    "type": "python"
  },
  "name": "remove-statefulset",
  "type": "action"
}
name: remove-statefulset
provider:
  func: remove_statefulset
  module: chaosk8s.statefulset.actions
  type: python
type: action

scale_statefulset

Type action
Module chaosk8s.statefulset.actions
Name scale_statefulset
Return None

Scale a stateful set up or down. The name is the name of the stateful set.

Signature:

def scale_statefulset(name: str,
                      replicas: int,
                      ns: str = 'default',
                      secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
replicas integer Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.statefulset.actions",
    "func": "scale_statefulset",
    "arguments": {
      "replicas": 0,
      "name": ""
    },
    "type": "python"
  },
  "name": "scale-statefulset",
  "type": "action"
}
name: scale-statefulset
provider:
  arguments:
    name: ''
    replicas: 0
  func: scale_statefulset
  module: chaosk8s.statefulset.actions
  type: python
type: action

statefulset_fully_available

Type probe
Module chaosk8s.statefulset.probes
Name statefulset_fully_available
Return None

Wait until all the statefulSet expected replicas are available. Once this state is reached, return True. If the state is not reached after timeout seconds, a :exc:chaoslib.exceptions.ActivityFailed exception is raised.

Signature:

def statefulset_fully_available(name: str,
                                ns: str = 'default',
                                label_selector: str = None,
                                timeout: int = 30,
                                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.statefulset.probes",
    "func": "statefulset_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "statefulset-fully-available",
  "type": "probe"
}
name: statefulset-fully-available
provider:
  arguments:
    name: ''
  func: statefulset_fully_available
  module: chaosk8s.statefulset.probes
  type: python
type: probe

statefulset_not_fully_available

Type probe
Module chaosk8s.statefulset.probes
Name statefulset_not_fully_available
Return None

Wait until the statefulSet gets into an intermediate state where not all expected replicas are available. Once this state is reached, return True. If the state is not reached after timeout seconds, a :exc:chaoslib.exceptions.ActivityFailed exception is raised.

Signature:

def statefulset_not_fully_available(name: str,
                                    ns: str = 'default',
                                    label_selector: str = None,
                                    timeout: int = 30,
                                    secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.statefulset.probes",
    "func": "statefulset_not_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "statefulset-not-fully-available",
  "type": "probe"
}
name: statefulset-not-fully-available
provider:
  arguments:
    name: ''
  func: statefulset_not_fully_available
  module: chaosk8s.statefulset.probes
  type: python
type: probe

pod


count_pods

Type probe
Module chaosk8s.pod.probes
Name count_pods
Return integer

Count the number of pods matching the given selector in a given phase, if one is given.

Signature:

def count_pods(label_selector: str,
               phase: str = None,
               ns: str = 'default',
               secrets: Dict[str, Dict[str, str]] = None) -> int:
    pass

Arguments:

Name Type Default Required
label_selector string Yes
phase string null No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "count_pods",
    "arguments": {
      "label_selector": ""
    },
    "type": "python"
  },
  "name": "count-pods",
  "type": "probe"
}
name: count-pods
provider:
  arguments:
    label_selector: ''
  func: count_pods
  module: chaosk8s.pod.probes
  type: python
type: probe

delete_pods

Type action
Module chaosk8s.pod.actions
Name delete_pods
Return None

Delete pods by name in the namespace ns.

The pods are deleted without a graceful period to trigger an abrupt termination.

The selected resources are matched by the given label_selector.

Signature:

def delete_pods(name: str,
                ns: str = 'default',
                label_selector: str = 'name in ({name})',
                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.actions",
    "func": "delete_pods",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "delete-pods",
  "type": "action"
}
name: delete-pods
provider:
  arguments:
    name: ''
  func: delete_pods
  module: chaosk8s.pod.actions
  type: python
type: action

exec_in_pods

Type action
Module chaosk8s.pod.actions
Name exec_in_pods
Return list

Execute the command cmd in the specified pod’s container. Select the appropriate pods by label and/or name patterns. Whenever a pattern is provided for the name, all pods retrieved will be filtered out if their name do not match the given pattern.

If neither label_selector nor name_pattern are provided, all pods in the namespace will be selected for termination.

If all is set to True, all matching pods will be affected.

Value of qty varies based on mode. If mode is set to fixed, then qty refers to number of pods affected. If mode is set to percentage, then qty refers to percentage of pods, from 1 to 100, to be affected. Default mode is fixed and default qty is 1.

If order is set to oldest, the retrieved pods will be ordered by the pods creation_timestamp, with the oldest pod first in list.

If rand is set to True, n random pods will be affected Otherwise, the first retrieved n pods will be used

Signature:

def exec_in_pods(
        cmd: str,
        label_selector: str = None,
        name_pattern: str = None,
        all: bool = False,
        rand: bool = False,
        mode: str = 'fixed',
        qty: int = 1,
        ns: str = 'default',
        order: str = 'alphabetic',
        container_name: str = None,
        request_timeout: int = 60,
        secrets: Dict[str, Dict[str, str]] = None) -> List[Dict[str, Any]]:
    pass

Arguments:

Name Type Default Required
cmd string Yes
label_selector string null No
name_pattern string null No
all boolean false No
rand boolean false No
mode string “fixed” No
qty integer 1 No
ns string “default” No
order string “alphabetic” No
container_name string null No
request_timeout integer 60 No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.actions",
    "func": "exec_in_pods",
    "arguments": {
      "cmd": ""
    },
    "type": "python"
  },
  "name": "exec-in-pods",
  "type": "action"
}
name: exec-in-pods
provider:
  arguments:
    cmd: ''
  func: exec_in_pods
  module: chaosk8s.pod.actions
  type: python
type: action

pod_is_not_available

Type probe
Module chaosk8s.pod.probes
Name pod_is_not_available
Return boolean

Lookup pods with a name label set to the given name in the specified ns.

Raises :exc:chaoslib.exceptions.ActivityFailed when one of the pods with the specified name is in the "Running" phase.

Signature:

def pod_is_not_available(name: str,
                         ns: str = 'default',
                         label_selector: str = 'name in ({name})',
                         secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "pod_is_not_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "pod-is-not-available",
  "type": "probe"
}
name: pod-is-not-available
provider:
  arguments:
    name: ''
  func: pod_is_not_available
  module: chaosk8s.pod.probes
  type: python
type: probe

pods_in_conditions

Type probe
Module chaosk8s.pod.probes
Name pods_in_conditions
Return boolean

Lookup a pod by label_selector in the namespace ns.

Raises :exc:chaoslib.exceptions.ActivityFailed if one of the given conditions type/status is not as expected

Signature:

def pods_in_conditions(label_selector: str,
                       conditions: List[Dict[str, str]],
                       ns: str = 'default',
                       secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
label_selector string Yes
conditions list Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "pods_in_conditions",
    "arguments": {
      "conditions": [],
      "label_selector": ""
    },
    "type": "python"
  },
  "name": "pods-in-conditions",
  "type": "probe"
}
name: pods-in-conditions
provider:
  arguments:
    conditions: []
    label_selector: ''
  func: pods_in_conditions
  module: chaosk8s.pod.probes
  type: python
type: probe

pods_in_phase

Type probe
Module chaosk8s.pod.probes
Name pods_in_phase
Return boolean

Lookup a pod by label_selector in the namespace ns.

Raises :exc:chaoslib.exceptions.ActivityFailed when the state is not as expected.

Signature:

def pods_in_phase(label_selector: str,
                  phase: str = 'Running',
                  ns: str = 'default',
                  secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
label_selector string Yes
phase string “Running” No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "pods_in_phase",
    "arguments": {
      "label_selector": ""
    },
    "type": "python"
  },
  "name": "pods-in-phase",
  "type": "probe"
}
name: pods-in-phase
provider:
  arguments:
    label_selector: ''
  func: pods_in_phase
  module: chaosk8s.pod.probes
  type: python
type: probe

pods_not_in_phase

Type probe
Module chaosk8s.pod.probes
Name pods_not_in_phase
Return boolean

Lookup a pod by label_selector in the namespace ns.

Raises :exc:chaoslib.exceptions.ActivityFailed when the pod is in the given phase and should not have.

Signature:

def pods_not_in_phase(label_selector: str,
                      phase: str = 'Running',
                      ns: str = 'default',
                      secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
label_selector string Yes
phase string “Running” No
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "pods_not_in_phase",
    "arguments": {
      "label_selector": ""
    },
    "type": "python"
  },
  "name": "pods-not-in-phase",
  "type": "probe"
}
name: pods-not-in-phase
provider:
  arguments:
    label_selector: ''
  func: pods_not_in_phase
  module: chaosk8s.pod.probes
  type: python
type: probe

read_pod_logs

Type probe
Module chaosk8s.pod.probes
Name read_pod_logs
Return mapping

Fetch logs for all the pods with the label "name" set to name and return a dictionary with the keys being the pod’s name and the values the logs of said pod. If name is not provided, use only the label_selector instead.

When your pod has several containers, you should also set container_name to clarify which container you want to read logs from.

If you provide last, this returns the logs of the last N seconds until now. This can set to a fluent delta such as 10 minutes.

You may also set from_previous to True to capture the logs of a previous pod’s incarnation, if any.

Signature:

def read_pod_logs(name: str = None,
                  last: Union[str, NoneType] = None,
                  ns: str = 'default',
                  from_previous: bool = False,
                  label_selector: str = 'name in ({name})',
                  container_name: str = None,
                  secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, str]:
    pass

Arguments:

Name Type Default Required
name string null No
last object null No
ns string “default” No
from_previous boolean false No
label_selector string “name in ({name})” No
container_name string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.probes",
    "func": "read_pod_logs",
    "type": "python"
  },
  "name": "read-pod-logs",
  "type": "probe"
}
name: read-pod-logs
provider:
  func: read_pod_logs
  module: chaosk8s.pod.probes
  type: python
type: probe

terminate_pods

Type action
Module chaosk8s.pod.actions
Name terminate_pods
Return None

Terminate a pod gracefully. Select the appropriate pods by label and/or name patterns. Whenever a pattern is provided for the name, all pods retrieved will be filtered out if their name do not match the given pattern.

If neither label_selector nor name_pattern are provided, all pods in the namespace will be selected for termination.

If all is set to True, all matching pods will be terminated.

Value of qty varies based on mode. If mode is set to fixed, then qty refers to number of pods to be terminated. If mode is set to percentage, then qty refers to percentage of pods, from 1 to 100, to be terminated. Default mode is fixed and default qty is 1.

If order is set to oldest, the retrieved pods will be ordered by the pods creation_timestamp, with the oldest pod first in list.

If rand is set to True, n random pods will be terminated Otherwise, the first retrieved n pods will be terminated.

If grace_period is greater than or equal to 0, it will be used as the grace period (in seconds) to terminate the pods. Otherwise, the default pod’s grace period will be used.

Signature:

def terminate_pods(label_selector: str = None,
                   name_pattern: str = None,
                   all: bool = False,
                   rand: bool = False,
                   mode: str = 'fixed',
                   qty: int = 1,
                   grace_period: int = -1,
                   ns: str = 'default',
                   order: str = 'alphabetic',
                   secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
label_selector string null No
name_pattern string null No
all boolean false No
rand boolean false No
mode string “fixed” No
qty integer 1 No
grace_period integer -1 No
ns string “default” No
order string “alphabetic” No

Usage:

{
  "provider": {
    "module": "chaosk8s.pod.actions",
    "func": "terminate_pods",
    "type": "python"
  },
  "name": "terminate-pods",
  "type": "action"
}
name: terminate-pods
provider:
  func: terminate_pods
  module: chaosk8s.pod.actions
  type: python
type: action

service


create_service_endpoint

Type action
Module chaosk8s.service.actions
Name create_service_endpoint
Return None

Create a service endpoint described by the service config, which must be the path to the JSON or YAML representation of the service.

Signature:

def create_service_endpoint(spec_path: str,
                            ns: str = 'default',
                            secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
spec_path string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.service.actions",
    "func": "create_service_endpoint",
    "arguments": {
      "spec_path": ""
    },
    "type": "python"
  },
  "name": "create-service-endpoint",
  "type": "action"
}
name: create-service-endpoint
provider:
  arguments:
    spec_path: ''
  func: create_service_endpoint
  module: chaosk8s.service.actions
  type: python
type: action

delete_service

Type action
Module chaosk8s.service.actions
Name delete_service
Return None

Remove the given service

Signature:

def delete_service(name: str,
                   ns: str = 'default',
                   secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.service.actions",
    "func": "delete_service",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "delete-service",
  "type": "action"
}
name: delete-service
provider:
  arguments:
    name: ''
  func: delete_service
  module: chaosk8s.service.actions
  type: python
type: action

service_is_initialized

Type probe
Module chaosk8s.service.probes
Name service_is_initialized
Return boolean

Lookup a service endpoint by its name and raises :exc:FailedProbe when the service was not found or not initialized.

Signature:

def service_is_initialized(name: str = None,
                           ns: str = 'default',
                           label_selector: str = None,
                           secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
name string null No
ns string “default” No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.service.probes",
    "func": "service_is_initialized",
    "type": "python"
  },
  "name": "service-is-initialized",
  "type": "probe"
}
name: service-is-initialized
provider:
  func: service_is_initialized
  module: chaosk8s.service.probes
  type: python
type: probe

node


cordon_node

Type action
Module chaosk8s.node.actions
Name cordon_node
Return None

Cordon nodes matching the given label or name, so that no pods are scheduled on them any longer.

Signature:

def cordon_node(name: str = None,
                label_selector: str = None,
                secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string null No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "func": "cordon_node",
    "type": "python"
  },
  "name": "cordon-node",
  "type": "action"
}
name: cordon-node
provider:
  func: cordon_node
  module: chaosk8s.node.actions
  type: python
type: action

create_node

Type action
Module chaosk8s.node.actions
Name create_node
Return kubernetes.client.models.v1_node.V1Node

Create one new node in the cluster.

Due to the way things work on certain cloud providers, you won’t be able to use this meaningfully on them. For instance on GCE, this will likely fail.

See also: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency

Signature:

def create_node(
    meta: Dict[str, Any] = None,
    spec: Dict[str, Any] = None,
    secrets: Dict[str, Dict[str, str]] = None
) -> kubernetes.client.models.v1_node.V1Node:
    pass

Arguments:

Name Type Default Required
meta mapping null No
spec mapping null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "func": "create_node",
    "type": "python"
  },
  "name": "create-node",
  "type": "action"
}
name: create-node
provider:
  func: create_node
  module: chaosk8s.node.actions
  type: python
type: action

delete_nodes

Type action
Module chaosk8s.node.actions
Name delete_nodes
Return None

Delete nodes gracefully. Select the appropriate nodes by label.

Nodes are not drained beforehand so we can see how cluster behaves. Nodes cannot be restarted, they are really deleted. Please be careful when using this action.

On certain cloud providers, you also need to delete the underneath VM instance as well afterwards. This is the case on GCE for instance.

If all is set to True, all nodes will be terminated. If rand is set to True, one random node will be terminated. If ̀count is set to a positive number, only a upto count nodes (randomly picked) will be terminated. Otherwise, the first retrieved node will be terminated.

Signature:

def delete_nodes(label_selector: str = None,
                 all: bool = False,
                 rand: bool = False,
                 count: int = None,
                 grace_period_seconds: int = None,
                 secrets: Dict[str, Dict[str, str]] = None,
                 pod_label_selector: str = None,
                 pod_namespace: str = None):
    pass

Arguments:

Name Type Default Required
label_selector string null No
all boolean false No
rand boolean false No
count integer null No
grace_period_seconds integer null No
pod_label_selector string null No
pod_namespace string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "func": "delete_nodes",
    "type": "python"
  },
  "name": "delete-nodes",
  "type": "action"
}
name: delete-nodes
provider:
  func: delete_nodes
  module: chaosk8s.node.actions
  type: python
type: action

drain_nodes

Type action
Module chaosk8s.node.actions
Name drain_nodes
Return boolean

Drain nodes matching the given label or name, so that no pods are scheduled on them any longer and running pods are evicted.

It does a similar job to kubectl drain --ignore-daemonsets or kubectl drain --delete-local-data --ignore-daemonsets if delete_pods_with_local_storage is set to True. There is no equivalent to the kubectl drain --force flag.

You probably want to call uncordon from in your experiment’s rollbacks.

Signature:

def drain_nodes(name: str = None,
                label_selector: str = None,
                delete_pods_with_local_storage: bool = False,
                timeout: int = 120,
                secrets: Dict[str, Dict[str, str]] = None,
                count: int = None,
                pod_label_selector: str = None,
                pod_namespace: str = None) -> bool:
    pass

Arguments:

Name Type Default Required
name string null No
label_selector string null No
delete_pods_with_local_storage boolean false No
timeout integer 120 No
count integer null No
pod_label_selector string null No
pod_namespace string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "func": "drain_nodes",
    "type": "python"
  },
  "name": "drain-nodes",
  "type": "action"
}
name: drain-nodes
provider:
  func: drain_nodes
  module: chaosk8s.node.actions
  type: python
type: action

get_nodes

Type probe
Module chaosk8s.node.probes
Name get_nodes
Return None

List all Kubernetes worker nodes in your cluster. You may filter nodes by specifying a label selector.

Signature:

def get_nodes(label_selector: str = None,
              configuration: Dict[str, Dict[str, str]] = None,
              secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.probes",
    "func": "get_nodes",
    "type": "python"
  },
  "name": "get-nodes",
  "type": "probe"
}
name: get-nodes
provider:
  func: get_nodes
  module: chaosk8s.node.probes
  type: python
type: probe

uncordon_node

Type action
Module chaosk8s.node.actions
Name uncordon_node
Return None

Uncordon nodes matching the given label name, so that pods can be scheduled on them again.

Signature:

def uncordon_node(name: str = None,
                  label_selector: str = None,
                  secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string null No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "func": "uncordon_node",
    "type": "python"
  },
  "name": "uncordon-node",
  "type": "action"
}
name: uncordon-node
provider:
  func: uncordon_node
  module: chaosk8s.node.actions
  type: python
type: action

replicaset


delete_replica_set

Type action
Module chaosk8s.replicaset.actions
Name delete_replica_set
Return None

Delete a replica set by name in the namespace ns.

The replica set is deleted without a graceful period to trigger an abrupt termination.

The selected resources are matched by the given label_selector.

Signature:

def delete_replica_set(name: str,
                       ns: str = 'default',
                       label_selector: str = 'name in ({name})',
                       secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.replicaset.actions",
    "func": "delete_replica_set",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "delete-replica-set",
  "type": "action"
}
name: delete-replica-set
provider:
  arguments:
    name: ''
  func: delete_replica_set
  module: chaosk8s.replicaset.actions
  type: python
type: action

probes


all_microservices_healthy

Type probe
Module chaosk8s.probes
Name all_microservices_healthy
Return Tuple[Dict[str, Any], Dict[str, Any]]

!!!DEPRECATED!!!

Signature:

def all_microservices_healthy(
    ns: str = 'default',
    secrets: Dict[str, Dict[str, str]] = None
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
    pass

Arguments:

Name Type Default Required
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "all_microservices_healthy",
    "type": "python"
  },
  "name": "all-microservices-healthy",
  "type": "probe"
}
name: all-microservices-healthy
provider:
  func: all_microservices_healthy
  module: chaosk8s.probes
  type: python
type: probe

deployment_is_fully_available

Type probe
Module chaosk8s.probes
Name deployment_is_fully_available
Return None

!!!DEPRECATED!!!

Signature:

def deployment_is_fully_available(name: str,
                                  ns: str = 'default',
                                  label_selector: str = None,
                                  timeout: int = 30,
                                  secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "deployment_is_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "deployment-is-fully-available",
  "type": "probe"
}
name: deployment-is-fully-available
provider:
  arguments:
    name: ''
  func: deployment_is_fully_available
  module: chaosk8s.probes
  type: python
type: probe

deployment_is_not_fully_available

Type probe
Module chaosk8s.probes
Name deployment_is_not_fully_available
Return None

!!!DEPRECATED!!!

Signature:

def deployment_is_not_fully_available(name: str,
                                      ns: str = 'default',
                                      label_selector: str = None,
                                      timeout: int = 30,
                                      secrets: Dict[str, Dict[str,
                                                              str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "deployment_is_not_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "deployment-is-not-fully-available",
  "type": "probe"
}
name: deployment-is-not-fully-available
provider:
  arguments:
    name: ''
  func: deployment_is_not_fully_available
  module: chaosk8s.probes
  type: python
type: probe

microservice_available_and_healthy

Type probe
Module chaosk8s.probes
Name microservice_available_and_healthy
Return Union[bool, NoneType]

!!!DEPRECATED!!!

Signature:

def microservice_available_and_healthy(
        name: str,
        ns: str = 'default',
        label_selector: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Union[bool, NoneType]:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "microservice_available_and_healthy",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "microservice-available-and-healthy",
  "type": "probe"
}
name: microservice-available-and-healthy
provider:
  arguments:
    name: ''
  func: microservice_available_and_healthy
  module: chaosk8s.probes
  type: python
type: probe

microservice_is_not_available

Type probe
Module chaosk8s.probes
Name microservice_is_not_available
Return boolean

!!!DEPRECATED!!!

Signature:

def microservice_is_not_available(
        name: str,
        ns: str = 'default',
        label_selector: str = 'name in ({name})',
        secrets: Dict[str, Dict[str, str]] = None) -> bool:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "microservice_is_not_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "microservice-is-not-available",
  "type": "probe"
}
name: microservice-is-not-available
provider:
  arguments:
    name: ''
  func: microservice_is_not_available
  module: chaosk8s.probes
  type: python
type: probe

read_microservices_logs

Type probe
Module chaosk8s.probes
Name read_microservices_logs
Return mapping

Fetch logs for all the pods with the label "name" set to name and return a dictionary with the keys being the pod’s name and the values the logs of said pod. If name is not provided, use only the label_selector instead.

When your pod has several containers, you should also set container_name to clarify which container you want to read logs from.

If you provide last, this returns the logs of the last N seconds until now. This can set to a fluent delta such as 10 minutes.

You may also set from_previous to True to capture the logs of a previous pod’s incarnation, if any.

Signature:

def read_microservices_logs(
        name: str = None,
        last: Union[str, NoneType] = None,
        ns: str = 'default',
        from_previous: bool = False,
        label_selector: str = 'name in ({name})',
        container_name: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Dict[str, str]:
    pass

Arguments:

Name Type Default Required
name string null No
last object null No
ns string “default” No
from_previous boolean false No
label_selector string “name in ({name})” No
container_name string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "read_microservices_logs",
    "type": "python"
  },
  "name": "read-microservices-logs",
  "type": "probe"
}
name: read-microservices-logs
provider:
  func: read_microservices_logs
  module: chaosk8s.probes
  type: python
type: probe

service_endpoint_is_initialized

Type probe
Module chaosk8s.probes
Name service_endpoint_is_initialized
Return None

!!!DEPRECATED!!!

Signature:

def service_endpoint_is_initialized(name: str,
                                    ns: str = 'default',
                                    label_selector: str = 'name in ({name})',
                                    secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "func": "service_endpoint_is_initialized",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "service-endpoint-is-initialized",
  "type": "probe"
}
name: service-endpoint-is-initialized
provider:
  arguments:
    name: ''
  func: service_endpoint_is_initialized
  module: chaosk8s.probes
  type: python
type: probe

deployment


create_deployment

Type action
Module chaosk8s.deployment.actions
Name create_deployment
Return None

Create a deployment described by the deployment config, which must be the path to the JSON or YAML representation of the deployment.

Signature:

def create_deployment(spec_path: str,
                      ns: str = 'default',
                      secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
spec_path string Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.actions",
    "func": "create_deployment",
    "arguments": {
      "spec_path": ""
    },
    "type": "python"
  },
  "name": "create-deployment",
  "type": "action"
}
name: create-deployment
provider:
  arguments:
    spec_path: ''
  func: create_deployment
  module: chaosk8s.deployment.actions
  type: python
type: action

delete_deployment

Type action
Module chaosk8s.deployment.actions
Name delete_deployment
Return None

Delete a deployment by name in the namespace ns.

The deployment is deleted without a graceful period to trigger an abrupt termination.

The selected resources are matched by the given label_selector.

Signature:

def delete_deployment(name: str,
                      ns: str = 'default',
                      label_selector: str = 'name in ({name})',
                      secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.actions",
    "func": "delete_deployment",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "delete-deployment",
  "type": "action"
}
name: delete-deployment
provider:
  arguments:
    name: ''
  func: delete_deployment
  module: chaosk8s.deployment.actions
  type: python
type: action

deployment_available_and_healthy

Type probe
Module chaosk8s.deployment.probes
Name deployment_available_and_healthy
Return Union[bool, NoneType]

Lookup a deployment by name in the namespace ns.

The selected resources are matched by the given label_selector.

Raises :exc:chaoslib.exceptions.ActivityFailed when the state is not as expected.

Signature:

def deployment_available_and_healthy(
        name: str,
        ns: str = 'default',
        label_selector: str = None,
        secrets: Dict[str, Dict[str, str]] = None) -> Union[bool, NoneType]:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.probes",
    "func": "deployment_available_and_healthy",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "deployment-available-and-healthy",
  "type": "probe"
}
name: deployment-available-and-healthy
provider:
  arguments:
    name: ''
  func: deployment_available_and_healthy
  module: chaosk8s.deployment.probes
  type: python
type: probe

deployment_fully_available

Type probe
Module chaosk8s.deployment.probes
Name deployment_fully_available
Return Union[bool, NoneType]

Wait until all the deployment expected replicas are available. Once this state is reached, return True. If the state is not reached after timeout seconds, a :exc:chaoslib.exceptions.ActivityFailed exception is raised.

Signature:

def deployment_fully_available(
        name: str,
        ns: str = 'default',
        label_selector: str = None,
        timeout: int = 30,
        secrets: Dict[str, Dict[str, str]] = None) -> Union[bool, NoneType]:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.probes",
    "func": "deployment_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "deployment-fully-available",
  "type": "probe"
}
name: deployment-fully-available
provider:
  arguments:
    name: ''
  func: deployment_fully_available
  module: chaosk8s.deployment.probes
  type: python
type: probe

deployment_not_fully_available

Type probe
Module chaosk8s.deployment.probes
Name deployment_not_fully_available
Return Union[bool, NoneType]

Wait until the deployment gets into an intermediate state where not all expected replicas are available. Once this state is reached, return True. If the state is not reached after timeout seconds, a :exc:chaoslib.exceptions.ActivityFailed exception is raised.

Signature:

def deployment_not_fully_available(
        name: str,
        ns: str = 'default',
        label_selector: str = None,
        timeout: int = 30,
        secrets: Dict[str, Dict[str, str]] = None) -> Union[bool, NoneType]:
    pass

Arguments:

Name Type Default Required
name string Yes
ns string “default” No
label_selector string null No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.probes",
    "func": "deployment_not_fully_available",
    "arguments": {
      "name": ""
    },
    "type": "python"
  },
  "name": "deployment-not-fully-available",
  "type": "probe"
}
name: deployment-not-fully-available
provider:
  arguments:
    name: ''
  func: deployment_not_fully_available
  module: chaosk8s.deployment.probes
  type: python
type: probe

scale_deployment

Type action
Module chaosk8s.deployment.actions
Name scale_deployment
Return None

Scale a deployment up or down. The name is the name of the deployment.

Signature:

def scale_deployment(name: str,
                     replicas: int,
                     ns: str = 'default',
                     secrets: Dict[str, Dict[str, str]] = None):
    pass

Arguments:

Name Type Default Required
name string Yes
replicas integer Yes
ns string “default” No

Usage:

{
  "provider": {
    "module": "chaosk8s.deployment.actions",
    "func": "scale_deployment",
    "arguments": {
      "replicas": 0,
      "name": ""
    },
    "type": "python"
  },
  "name": "scale-deployment",
  "type": "action"
}
name: scale-deployment
provider:
  arguments:
    name: ''
    replicas: 0
  func: scale_deployment
  module: chaosk8s.deployment.actions
  type: python
type: action