How krkn-chaos/krkn works
Purpose and Entry Points
Krkn (Kraken) is a Python chaos/resiliency test runner for Kubernetes, OpenShift, Kind, and KubeVirt clusters. It deliberately injects infrastructure and workload failures, then evaluates cluster/application health. Primary launch surfaces are run_kraken.py, the optional HTTP service server.py, and container startup containers/entrypoint.sh.
Configuration-to-Execution Orchestration
A run combines a global configuration with one or more scenario YAML files. Environment-specific defaults and metric/alert definitions reside in config/config.yaml, config/config_kubernetes.yaml, and config/config_kind.yaml; executable examples are under scenarios/openshift/, scenarios/kube/, and scenarios/kind/. The runner parses selected scenarios, creates plugins through the central factory, executes them, and collects failures/results.
Scenario Plugin Boundary
krkn/scenario_plugins/scenario_plugin_factory.py is the extension and dispatch boundary, backed by krkn/scenario_plugins/abstract_scenario_plugin.py. Each plugin encapsulates a chaos operation and its lifecycle against the target cluster. Major plugin families include workload/pod disruption (krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py), cloud or physical node actions (krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py), and application/service disruptions (krkn/scenario_plugins/application_outage/application_outage_scenario_plugin.py).
Fault Injection Implementations
Plugins act through Kubernetes APIs, rendered workload/job manifests, host/cloud controls, or shell commands. Network chaos has both template-driven and modular implementations: krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py and krkn/scenario_plugins/network_chaos_ng/network_chaos_ng_scenario_plugin.py; the latter selects specialized node, pod, and VMI modules. Node-action adapters isolate provider-specific behavior for AWS, Azure, GCP, OpenStack, VMware, IBM Cloud, Alibaba, Docker, and bare metal under krkn/scenario_plugins/node_actions/.
Health, Metrics, and Resiliency Assessment
Health checking is plugin-based: krkn/health_checks/health_check_factory.py selects simple, HTTP, or virtual-machine checks defined by the abstract contract in krkn/health_checks/abstract_health_check_plugin.py. Prometheus integration (krkn/prometheus/client.py, krkn/prometheus/collector.py) queries and records telemetry. Resiliency evaluation and scoring are separated in krkn/resiliency/resiliency.py and krkn/resiliency/score.py; alert and metric definitions are supplied through files such as config/alerts.yaml and config/metrics.yaml.
Safety, Rollback, and Triggers
Rollback is a first-class recovery boundary: krkn/rollback/handler.py coordinates serialized rollback commands/configuration from krkn/rollback/command.py and krkn/rollback/config.py, including signal-related handling. Scenario execution can be gated or augmented by command triggers via krkn/scenario_plugins/triggers/trigger_manager.py. This separates fault initiation from compensating actions and failure accumulation.
Deployment and External Dependencies
Krkn runs as a local Python process or container image, with image assembly under containers/Dockerfile.template. It requires credentials/RBAC to modify cluster resources; privileged and non-privileged deployment roles are in rbac/privileged-clusterrole.yaml and rbac/non-privileged-role.yaml. External control planes can include Kubernetes/OpenShift APIs, supported cloud-provider APIs, Prometheus, and optionally Cerberus (krkn/cerberus/setup.py) for cluster health validation. Ansible deployment assets are provided in ansible/kraken.yml.
Main entry points: run_kraken.py CLI runner · scenario_plugin_factory.py Scenario factory · health_check_factory.py Health check factory · collector.py Prometheus collector
Components 20
Launch & config
- CLI runner · Builds and runs selected chaos scenarios.
run_kraken.py - HTTP service
server.py - Container startup
containers/entrypoint.sh - Global & scenario YAML · Supplies defaults, metrics, alerts, and executable scenarios.
config/config.yaml
Scenario execution
- Scenario factory · Creates scenario plugins from parsed configuration.
krkn/scenario_plugins/scenario_plugin_factory.py - Scenario plugin contract
krkn/scenario_plugins/abstract_scenario_plugin.py - Workload & app disruption · Pod disruption and application outage lifecycles.
krkn/scenario_plugins/pod_disruption/pod_disruption_scenario_plugin.py - Node action adapters · Isolates cloud, physical-host, Docker, and bare-metal actions.
krkn/scenario_plugins/node_actions/node_actions_scenario_plugin.py - Network chaos · Template-driven and modular node, pod, and VMI network faults.
krkn/scenario_plugins/network_chaos/network_chaos_scenario_plugin.py - Trigger manager
krkn/scenario_plugins/triggers/trigger_manager.py
Health & assessment
- Health check factory · Selects simple, HTTP, or virtual-machine checks.
krkn/health_checks/health_check_factory.py - Health check contract
krkn/health_checks/abstract_health_check_plugin.py - Prometheus collector · Queries and records cluster telemetry.
krkn/prometheus/collector.py - Resiliency scoring · Evaluates results and computes resiliency scores.
krkn/resiliency/resiliency.py
Recovery
- Rollback handler · Coordinates serialized compensating actions and signal handling.
krkn/rollback/handler.py - Rollback commands
krkn/rollback/command.py
Target environment
- Cluster APIs · Kubernetes or OpenShift resources require credentials and RBAC.
- Cloud & host controls · Provider APIs and host controls perform node actions.
- Prometheus
- Cerberus · Optional cluster health validation.
krkn/cerberus/setup.py
Connections 23
- Container startup → CLI runner: starts
- HTTP service → CLI runner: invokes runs
- Global & scenario YAML → CLI runner: configures
- CLI runner → Scenario factory: creates scenarios
- Scenario factory → Scenario plugin contract: implements
- Scenario factory → Workload & app disruption: selects
- Scenario factory → Node action adapters: selects
- Scenario factory → Network chaos: selects
- Trigger manager → Workload & app disruption: gates or augments
- Workload & app disruption → Cluster APIs: injects faults
- Network chaos → Cluster APIs: injects faults
- Node action adapters → Cloud & host controls: controls nodes
- CLI runner → Health check factory: runs checks
- Health check factory → Health check contract: implements
- Health check factory → Cluster APIs: validates
- CLI runner → Prometheus collector: collects metrics
- Prometheus collector → Prometheus: queries
- Prometheus collector → Resiliency scoring: provides telemetry
- Health check factory → Resiliency scoring: provides health results
- CLI runner → Rollback handler: recovers on failure
- Rollback handler → Rollback commands: executes
- Rollback handler → Cluster APIs: compensates
- Health check factory → Cerberus: optional validation