{"id":19282430,"url":"https://github.com/chaostoolkit/chaostoolkit-kubernetes","last_synced_at":"2025-09-23T19:04:43.369Z","repository":{"id":41460147,"uuid":"105543629","full_name":"chaostoolkit/chaostoolkit-kubernetes","owner":"chaostoolkit","description":"Kubernetes driver extension of the Chaos Toolkit probes and actions API","archived":false,"fork":false,"pushed_at":"2024-06-21T18:18:09.000Z","size":472,"stargazers_count":190,"open_issues_count":38,"forks_count":79,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-09-01T15:09:46.437Z","etag":null,"topics":["chaos-engineering","chaostoolkit-extension","cloud-native","kubernetes"],"latest_commit_sha":null,"homepage":"https://chaostoolkit.org/drivers/kubernetes/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chaostoolkit.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-02T14:23:07.000Z","updated_at":"2025-07-07T08:11:41.000Z","dependencies_parsed_at":"2023-09-22T14:13:35.324Z","dependency_job_id":"4c108685-df2e-4e3b-a7d7-1ee4c0a1d329","html_url":"https://github.com/chaostoolkit/chaostoolkit-kubernetes","commit_stats":null,"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"purl":"pkg:github/chaostoolkit/chaostoolkit-kubernetes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaostoolkit%2Fchaostoolkit-kubernetes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaostoolkit%2Fchaostoolkit-kubernetes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaostoolkit%2Fchaostoolkit-kubernetes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaostoolkit%2Fchaostoolkit-kubernetes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chaostoolkit","download_url":"https://codeload.github.com/chaostoolkit/chaostoolkit-kubernetes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chaostoolkit%2Fchaostoolkit-kubernetes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276631130,"owners_count":25676658,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chaos-engineering","chaostoolkit-extension","cloud-native","kubernetes"],"created_at":"2024-11-09T21:26:54.735Z","updated_at":"2025-09-23T19:04:43.350Z","avatar_url":"https://github.com/chaostoolkit.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chaos Toolkit Extensions for Kubernetes\n\n[![Build](https://github.com/chaostoolkit/chaostoolkit-kubernetes/actions/workflows/build.yaml/badge.svg)](https://github.com/chaostoolkit/chaostoolkit-kubernetes/actions/workflows/build.yaml)\n[![Python versions](https://img.shields.io/pypi/pyversions/chaostoolkit-kubernetes.svg)](https://www.python.org/)\n[![Downloads](https://pepy.tech/badge/chaostoolkit-kubernetes)](https://pepy.tech/project/chaostoolkit-kubernetes)\n\nThis project contains activities, such as probes and actions, you can call from\nyour experiment through the Chaos Toolkit to perform Chaos Engineering against\nthe Kubernetes API: killing a pod, removing a statefulset or node...\n\n## Install\n\nTo be used from your experiment, this package must be installed in the Python\nenvironment where [chaostoolkit][] already lives.\n\n[chaostoolkit]: https://github.com/chaostoolkit/chaostoolkit\n\n```\n$ pip install chaostoolkit-kubernetes\n```\n\n## Usage\n\nTo use the probes and actions from this package, add the following to your\nexperiment file:\n\n```json\n{\n    \"title\": \"Do we remain available in face of pod going down?\",\n    \"description\": \"We expect Kubernetes to handle the situation gracefully when a pod goes down\",\n    \"tags\": [\"kubernetes\"],\n    \"steady-state-hypothesis\": {\n        \"title\": \"Verifying service remains healthy\",\n        \"probes\": [\n            {\n                \"name\": \"all-our-microservices-should-be-healthy\",\n                \"type\": \"probe\",\n                \"tolerance\": true,\n                \"provider\": {\n                    \"type\": \"python\",\n                    \"module\": \"chaosk8s.probes\",\n                    \"func\": \"microservice_available_and_healthy\",\n                    \"arguments\": {\n                        \"name\": \"myapp\"\n                    }\n                }\n            }\n        ]\n    },\n    \"method\": [\n        {\n            \"type\": \"action\",\n            \"name\": \"terminate-db-pod\",\n            \"provider\": {\n                \"type\": \"python\",\n                \"module\": \"chaosk8s.pod.actions\",\n                \"func\": \"terminate_pods\",\n                \"arguments\": {\n                    \"label_selector\": \"app=my-app\",\n                    \"name_pattern\": \"my-app-[0-9]$\",\n                    \"rand\": true\n                }\n            },\n            \"pauses\": {\n                \"after\": 5\n            }\n        }\n    ]\n}\n```\n\nThat's it! Notice how the action gives you the way to kill one pod randomly.\n\nPlease explore the [documentation][doc] to see existing probes and actions.\n\n[doc]: https://chaostoolkit.org/drivers/kubernetes/#exported-activities\n\n### Low level fault injections\n\nNote, for the network, cpu and memory stressors we rely on the fantastic\n[Chaos Mesh project](https://chaos-mesh.org/) that provides a great interface\nto inject these faults.\n\nYou will need to install Chaos Mesh first in your cluster to use them.\n\n## Configuration\n\n### Use ~/.kube/config\n\nIf you have a valid entry in your `~/.kube/config` file for the cluster you\nwant to target, then there is nothing to be done.\n\nYou may specify `KUBECONFIG` to specify a different location.\n\n```\n$ export KUBECONFIG=/tmp/my-config\n```\n\n#### Specify the Kubernetes context\n\nQuite often, your Kubernetes configuration contains several entries, and you\nneed to define the one to use as a default context when it isn't\nexplicitly provided.\n\nYou may of course change your default using\n`kubectl config use-context KUBERNETES_CONTEXT` but you can also be explicit\nin your experiment as follows:\n\n```json\n{\n    \"title\": \"Do we remain available in face of pod going down?\",\n    \"description\": \"We expect Kubernetes to handle the situation gracefully when a pod goes down\",\n    \"tags\": [\"kubernetes\"],\n    \"secrets\": {\n        \"k8s\": {\n            \"KUBERNETES_CONTEXT\": \"...\"\n        }\n    },\n    \"steady-state-hypothesis\": {\n        \"title\": \"Verifying service remains healthy\",\n        \"probes\": [\n            {\n                \"name\": \"all-our-microservices-should-be-healthy\",\n                \"type\": \"probe\",\n                \"tolerance\": true,\n                \"secrets\": [\"k8s\"],\n                \"provider\": {\n                    \"type\": \"python\",\n                    \"module\": \"chaosk8s.probes\",\n                    \"func\": \"microservice_available_and_healthy\",\n                    \"arguments\": {\n                        \"name\": \"myapp\"\n                    }\n                }\n            }\n        ]\n    },\n    \"method\": [\n        {\n            \"type\": \"action\",\n            \"name\": \"terminate-db-pod\",\n            \"secrets\": [\"k8s\"],\n            \"provider\": {\n                \"type\": \"python\",\n                \"module\": \"chaosk8s.pod.actions\",\n                \"func\": \"terminate_pods\",\n                \"arguments\": {\n                    \"label_selector\": \"app=my-app\",\n                    \"name_pattern\": \"my-app-[0-9]$\",\n                    \"rand\": true\n                }\n            },\n            \"pauses\": {\n                \"after\": 5\n            }\n        }\n    ]\n}\n```\n\nYou need to specify the `KUBERNETES_CONTEXT` secret key to the name of the\ncontext you want the experiment to use. Make sure to also inform the\nactions and probes about the secret entries they should be\npassed `\"secrets\": [\"k8s\"]`.\n\n### Use a Pod's service account\n\nWhen running from a pod (not your local machine or a CI for instance), the\n `./.kube/config` file does not exist. Instead, the credentials can be found\n at [/var/run/secrets/kubernetes.io/serviceaccount/token][podcreds].\n\n [podcreds]: https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#accessing-the-api-from-a-pod\n\n To let the extension know about this, simply set `CHAOSTOOLKIT_IN_POD` from the\n environment variable of the pod specification:\n\n```yaml\nenv:\n- name: CHAOSTOOLKIT_IN_POD\n  value: \"true\"\n```\n\nWhen using this environment variable, it is assumed that the experiment\ntargets the same cluster where the experiment is running from. If your\nexperiment targets a different cluster, you should not set this variable.\nInstead, you could mount a volume with a Kubernetes config for the target\ncluster and set `KUBECONFIG` to point to it.\n\n## Pass all credentials in the experiment\n\nFinally, you may pass explicitly all required credentials information to the\nexperiment as follows:\n\n### Using an API key\n\n```json\n{\n    \"secrets\": {\n        \"kubernetes\": {\n            \"KUBERNETES_HOST\": \"http://somehost\",\n            \"KUBERNETES_API_KEY\": {\n                \"type\": \"env\",\n                \"key\": \"SOME_ENV_VAR\"\n            }\n        }\n    }\n}\n```\n\n### Using a username/password\n\n```json\n{\n    \"secrets\": {\n        \"kubernetes\": {\n            \"KUBERNETES_HOST\": \"http://somehost\",\n            \"KUBERNETES_USERNAME\": {\n                \"type\": \"env\",\n                \"key\": \"SOME_ENV_VAR\"\n            },\n            \"KUBERNETES_PASSWORD\": {\n                \"type\": \"env\",\n                \"key\": \"SOME_ENV_VAR\"\n            }\n        }\n    }\n}\n```\n\n### Using a TLS key/certificate\n\n```json\n{\n    \"secrets\": {\n        \"kubernetes\": {\n            \"KUBERNETES_HOST\": \"http://somehost\",\n            \"KUBERNETES_CERT_FILE\": {\n                \"type\": \"env\",\n                \"key\": \"SOME_ENV_VAR\"\n            },\n            \"KUBERNETES_KEY_FILE\": {\n                \"type\": \"env\",\n                \"key\": \"SOME_ENV_VAR\"\n            }\n        }\n    }\n}\n```\n\n## Managed Kubernetes Clusters Authentication\n\nOn some managed Kubernetes clusters, you also need to authenticate against the\nplatform itself because the Kubernetes authentication is delegated to it.\n\n### Google Cloud Platform\n\nIn addition to your Kubernetes credentials (via the `~/.kube/config` file), you\nneed to authenticate against the Google Cloud Platform itself. Usually this\nis done [via][gcloud]:\n\n[gcloud]: https://cloud.google.com/sdk/gcloud/reference/auth/login\n\n```\n$ gcloud auth login\n```\n\nBut can also be achieved by defining the `GOOGLE_APPLICATION_CREDENTIALS`\nenvironment variable.\n\n## Contribute\n\nIf you wish to contribute more functions to this package, you are more than\nwelcome to do so. Please, fork this project, write unit tests to cover the proposed changes,\nimplement the changes, ensure they meet the formatting standards and then raise a\nPR to the repository for review.\n\nPlease refer to the [formatting](#formatting-and-linting) section for more information\non the formatting standards.\n\nThe Chaos Toolkit projects require all contributors must sign a\n[Developer Certificate of Origin][dco] on each commit they would like to merge\ninto the master branch of the repository. Please, make sure you can abide by\nthe rules of the DCO before submitting a PR.\n\n[dco]: https://github.com/probot/dco#how-it-works\n\n### Develop\n\nIf you wish to develop on this project, make sure to install the development\ndependencies. But first, [install PDM][pdm] and then install\nthe dependencies.\n\n[pdm]: https://pdm-project.org/latest/\n\n```console\n$ pdm install\n```\n\nNow, you can edit the files, and they will be automatically be seen by your\nenvironment, even when running from the `chaos` command locally.\n\n### Tests\n\nTo run the tests for the project execute the following:\n\n```console\n$ pdm run tests\n```\n\n### Formatting and Linting\n\nWe use [ruff][] to both lint and format this repositories code.\n\n[ruff]: https://github.com/astral-sh/ruff\n\nBefore raising a Pull Request, we recommend you run formatting against your code with:\n\n```console\n$ pdm run format\n```\n\nThis will automatically format any code that doesn't adhere to the formatting standards.\n\nAs some things are not picked up by the formatting, we also recommend you run:\n\n```console\n$ pdm run lint\n```\n\nTo ensure that any unused import statements/strings that are too long, etc. are also picked up.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaostoolkit%2Fchaostoolkit-kubernetes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchaostoolkit%2Fchaostoolkit-kubernetes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchaostoolkit%2Fchaostoolkit-kubernetes/lists"}