{"id":13562405,"url":"https://github.com/ahmetb/kubectl-foreach","last_synced_at":"2025-05-15T23:03:06.616Z","repository":{"id":44172142,"uuid":"494659692","full_name":"ahmetb/kubectl-foreach","owner":"ahmetb","description":"Run kubectl commands in all/some contexts in parallel (similar to GNU xargs+parallel)","archived":false,"fork":false,"pushed_at":"2025-05-12T01:42:27.000Z","size":84,"stargazers_count":473,"open_issues_count":11,"forks_count":23,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-15T23:02:00.703Z","etag":null,"topics":["kubectl","kubectl-plugins"],"latest_commit_sha":null,"homepage":"","language":"Go","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/ahmetb.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"zenodo":null}},"created_at":"2022-05-21T02:29:17.000Z","updated_at":"2025-05-11T17:02:29.000Z","dependencies_parsed_at":"2025-02-23T18:13:00.090Z","dependency_job_id":"f42bd67e-7627-4fb8-a28a-42eb4c127ea5","html_url":"https://github.com/ahmetb/kubectl-foreach","commit_stats":null,"previous_names":["ahmetb/kubectl-allctx"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectl-foreach","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectl-foreach/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectl-foreach/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectl-foreach/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmetb","download_url":"https://codeload.github.com/ahmetb/kubectl-foreach/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254436944,"owners_count":22070946,"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","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":["kubectl","kubectl-plugins"],"created_at":"2024-08-01T13:01:08.281Z","updated_at":"2025-05-15T23:03:06.573Z","avatar_url":"https://github.com/ahmetb.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# kubectl foreach\n\nRun a `kubectl` command in one or more contexts (clusters) in parallel (similar\nto GNU parallel/xargs). Useful for querying multiple clusters at once or making\nchanges against the cluster fleet.\n\n## Usage\n\n```text\nUsage:\n    kubectl foreach [OPTIONS] [PATTERN]... -- [KUBECTL_ARGS...]\n\nPatterns can be used to match context names from kubeconfig:\n      (empty): matches all contexts\n         NAME: matches context with exact name\n    /PATTERN/: matches context with regular expression\n        ^NAME: remove context with exact name from the matched results\n   ^/PATTERN/: remove contexts matching the regular expression from the results\n\nOptions:\n    -c=NUM     Limit parallel executions (default: 0, unlimited)\n    -I=VAL     Replace VAL occurring in KUBECTL_ARGS with context name\n    -q         Disable and accept confirmation prompts ($KUBECTL_FOREACH_DISABLE_PROMPTS) \n    -h/--help  Print help\n```\n\n## Demo\n\nQuery a pod by label in `minikube` and `*-prod*` contexts:\n\n```text\n$ kubectl foreach /-prod/ minikube -- get pods -n kube-system --selector compute.twitter.com/app=coredns --no-headers\n\n     eu-prod | coredns-59bd9867bb-6rbx7   2/2     Running   0          78d\n     eu-prod | coredns-59bd9867bb-9xczh   2/2     Running   0          78d\n     eu-prod | coredns-59bd9867bb-fvn6t   2/2     Running   0          78d\n    minikube | No resources found in kube-system namespace.\n useast-prod | coredns-6fd4bd9db4-7w9wv   2/2     Running   0          78d\n useast-prod | coredns-6fd4bd9db4-9pk8n   2/2     Running   0          78d\n useast-prod | coredns-6fd4bd9db4-xphr4   2/2     Running   0          78d\n uswest-prod | coredns-6f987df9bc-6fgc2   2/2     Running   0          78d\n uswest-prod | coredns-6f987df9bc-9gxvt   2/2     Running   0          78d\n uswest-prod | coredns-6f987df9bc-d88jk   2/2     Running   0          78d\n```\n\n## Examples\n\n**Match to contexts by name:** Run a command (\"kubectl version\") on contexts `c1`, `c2`\nand `c3`:\n\n```sh\nkubectl foreach c1 c2 c3 -- version\n```\n\n**Match to contexts by pattern:** Run a command on contexts starting with `gke`\n(regular expression syntax):\n\n```sh\nkubectl foreach /^gke/ -- get pods\n```\n\n**Match all contexts:** empty context matches all contexts.\n\n```sh\nkubectl foreach -- version\n```\n\n**Excluding contexts:** Use the matching syntaxes with a `^` prefix to use them\nfor exclusion. If no matching contexts are specified.\n\ne.g. match all contexts **except** `c1` and except those ending\nwith `prod` (single quotes for escaping `$` in the shell):\n\n```shell\nkubectl foreach ^c1 ^/prod'$'/ -- version\n```\n\n**Using with kubectl plugins:** Customize how context name is passed to the command\n(useful for kubectl plugins as `--context` must be specified after plugin name).\n\nIn this example, `_` is replaced with the context name when calling \"kubectl\nmy_plugin\".\n\n```shell\nkubectl foreach -I _ -- my_plugin -ctx=_\n```\n\n**Limit parallelization:** Only run 3 commands at a time:\n\n```\nkubectl foreach -c 3 /^gke-/\n```\n\n## Install\n\nUse [Krew](https://krew.sigs.k8s.io/) kubectl plugin manager:\n\n```shell\nkubectl krew install foreach\n```\n\nYou can also build from source but you won't receive new version updates:\n```\ngo install github.com/ahmetb/kubectl-foreach@latest\n```\n\n## Remarks/FAQ\n\n**Do not use this tool programmatically:**\n\nThis tool is not intended for deploying workloads to clusters, or using\nprogrammatically. Therefore, it does not provide a structured output format or\nordered printing that is meant to be parsed by or piped to other programs (maybe\nexcept for `grep`).\n\n**error: pipe: too many open files:**\n\nmacOS default open files limit seems to be 256. kubectl command opens files\nand sockets that easily exhausts this number while running the command against\n50+ clusters. Run `ulimit -n 2048` to bump this limit to a higher number and\nyou should not be seeing the error anymore.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fkubectl-foreach","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmetb%2Fkubectl-foreach","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fkubectl-foreach/lists"}