Skip to content

Extension chaosk8s

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

N/A

Exported Activities

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",
    "type": "python",
    "arguments": {
      "label_selector": ""
    },
    "func": "count_pods"
  },
  "type": "probe",
  "name": "count-pods"
}
name: count-pods
provider:
  arguments:
    label_selector: ''
  func: count_pods
  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",
    "type": "python",
    "arguments": {
      "label_selector": ""
    },
    "func": "pods_in_phase"
  },
  "type": "probe",
  "name": "pods-in-phase"
}
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",
    "type": "python",
    "arguments": {
      "label_selector": ""
    },
    "func": "pods_not_in_phase"
  },
  "type": "probe",
  "name": "pods-not-in-phase"
}
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",
    "type": "python",
    "func": "read_pod_logs"
  },
  "type": "probe",
  "name": "read-pod-logs"
}
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 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',
                   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

Usage:

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

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",
    "type": "python",
    "func": "cordon_node"
  },
  "type": "action",
  "name": "cordon-node"
}
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",
    "type": "python",
    "func": "create_node"
  },
  "type": "action",
  "name": "create-node"
}
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):
    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

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "type": "python",
    "func": "delete_nodes"
  },
  "type": "action",
  "name": "delete-nodes"
}
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) -> 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

Usage:

{
  "provider": {
    "module": "chaosk8s.node.actions",
    "type": "python",
    "func": "drain_nodes"
  },
  "type": "action",
  "name": "drain-nodes"
}
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",
    "type": "python",
    "func": "get_nodes"
  },
  "type": "probe",
  "name": "get-nodes"
}
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",
    "type": "python",
    "func": "uncordon_node"
  },
  "type": "action",
  "name": "uncordon-node"
}
name: uncordon-node
provider:
  func: uncordon_node
  module: chaosk8s.node.actions
  type: python
type: action

actions


kill_microservice

Type action
Module chaosk8s.actions
Name kill_microservice
Return None

Kill a microservice by name in the namespace ns.

The microservice is killed by deleting the deployment for it without a graceful period to trigger an abrupt termination.

The selected resources are matched by the given label_selector.

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",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "kill_microservice"
  },
  "type": "action",
  "name": "kill-microservice"
}
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

Remove the service endpoint that sits in front of microservices (pods).

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",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "remove_service_endpoint"
  },
  "type": "action",
  "name": "remove-service-endpoint"
}
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

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

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",
    "type": "python",
    "arguments": {
      "replicas": 0,
      "name": ""
    },
    "func": "scale_microservice"
  },
  "type": "action",
  "name": "scale-microservice"
}
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

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

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",
    "type": "python",
    "arguments": {
      "spec_path": ""
    },
    "func": "start_microservice"
  },
  "type": "action",
  "name": "start-microservice"
}
name: start-microservice
provider:
  arguments:
    spec_path: ''
  func: start_microservice
  module: chaosk8s.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]]

Check all microservices in the system are running and available.

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

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",
    "type": "python",
    "func": "all_microservices_healthy"
  },
  "type": "probe",
  "name": "all-microservices-healthy"
}
name: all-microservices-healthy
provider:
  func: all_microservices_healthy
  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

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_is_not_fully_available(
        name: str,
        ns: str = 'default',
        label_selector: str = 'name in ({name})',
        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 “name in ({name})” No
timeout integer 30 No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "deployment_is_not_fully_available"
  },
  "type": "probe",
  "name": "deployment-is-not-fully-available"
}
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]

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 microservice_available_and_healthy(
        name: str,
        ns: str = 'default',
        label_selector: str = 'name in ({name})',
        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 “name in ({name})” No

Usage:

{
  "provider": {
    "module": "chaosk8s.probes",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "microservice_available_and_healthy"
  },
  "type": "probe",
  "name": "microservice-available-and-healthy"
}
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

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 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",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "microservice_is_not_available"
  },
  "type": "probe",
  "name": "microservice-is-not-available"
}
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",
    "type": "python",
    "func": "read_microservices_logs"
  },
  "type": "probe",
  "name": "read-microservices-logs"
}
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

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

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",
    "type": "python",
    "arguments": {
      "name": ""
    },
    "func": "service_endpoint_is_initialized"
  },
  "type": "probe",
  "name": "service-endpoint-is-initialized"
}
name: service-endpoint-is-initialized
provider:
  arguments:
    name: ''
  func: service_endpoint_is_initialized
  module: chaosk8s.probes
  type: python
type: probe