{"id":13452421,"url":"https://github.com/ahmetb/kubectx","last_synced_at":"2025-05-12T16:19:17.835Z","repository":{"id":37270102,"uuid":"86733463","full_name":"ahmetb/kubectx","owner":"ahmetb","description":"Faster way to switch between clusters and namespaces in kubectl","archived":false,"fork":false,"pushed_at":"2025-01-22T17:07:57.000Z","size":880,"stargazers_count":18573,"open_issues_count":66,"forks_count":1314,"subscribers_count":134,"default_branch":"master","last_synced_at":"2025-05-12T16:19:09.926Z","etag":null,"topics":["kubectl","kubectl-plugins","kubernetes","kubernetes-clusters"],"latest_commit_sha":null,"homepage":"https://kubectx.dev","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":"CONTRIBUTING.md","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":"2017-03-30T18:06:53.000Z","updated_at":"2025-05-12T15:49:26.000Z","dependencies_parsed_at":"2023-12-25T09:39:08.941Z","dependency_job_id":"9e3fa51f-8e97-452e-ada4-d590c90718b5","html_url":"https://github.com/ahmetb/kubectx","commit_stats":{"total_commits":238,"total_committers":64,"mean_commits":3.71875,"dds":0.4873949579831933,"last_synced_commit":"4997a261dca3af4ee346587000497e1b101590c1"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmetb%2Fkubectx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmetb","download_url":"https://codeload.github.com/ahmetb/kubectx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253774593,"owners_count":21962199,"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","kubernetes","kubernetes-clusters"],"created_at":"2024-07-31T07:01:23.716Z","updated_at":"2025-05-12T16:19:17.801Z","avatar_url":"https://github.com/ahmetb.png","language":"Go","funding_links":[],"categories":["Go","API/CLI adaptors","Tools","kubectl Plugins","kubernetes","CLI tools","Shell","Command Line Tools","Tools and Libraries","HarmonyOS","🏗相关开源项目","K8S-Tools","Kubernetes","\u003ca name=\"k8s\"\u003e\u003c/a\u003ek8s","一、核心工具集（按场景分类）","☸️ Kubernetes e Cloud Native","Docker \u0026 Kubernetes"],"sub_categories":["[Jenkins](#jenkins)","Examples","Installing plugins via awesome-kubectl-plugins","Command Line Tools","Windows Manager","有用的CLI工具","Kubernetes tools","1. 命令行效率工具（日常操作必备）","Ferramentas de Debugging"],"readme":"# `kubectx` + `kubens`: Power tools for kubectl\n\n![Latest GitHub release](https://img.shields.io/github/release/ahmetb/kubectx.svg)\n![GitHub stars](https://img.shields.io/github/stars/ahmetb/kubectx.svg?label=github%20stars)\n![Homebrew downloads](https://img.shields.io/homebrew/installs/dy/kubectx?label=macOS%20installs)\n[![Go implementation (CI)](https://github.com/ahmetb/kubectx/workflows/Go%20implementation%20(CI)/badge.svg)](https://github.com/ahmetb/kubectx/actions?query=workflow%3A\"Go+implementation+(CI)\")\n![Proudly written in Bash](https://img.shields.io/badge/written%20in-bash-ff69b4.svg)\n\nThis repository provides both `kubectx` and `kubens` tools.\n[Install \u0026rarr;](#installation)\n\n## What are `kubectx` and `kubens`?\n\n**kubectx** is a tool to switch between contexts (clusters) on kubectl\nfaster.\u003cbr/\u003e\n**kubens** is a tool to switch between Kubernetes namespaces (and\nconfigure them for kubectl) easily.\n\nHere's a **`kubectx`** demo:\n![kubectx demo GIF](img/kubectx-demo.gif)\n\n...and here's a **`kubens`** demo:\n![kubens demo GIF](img/kubens-demo.gif)\n\n### Examples\n\n```sh\n# switch to another cluster that's in kubeconfig\n$ kubectx minikube\nSwitched to context \"minikube\".\n\n# switch back to previous cluster\n$ kubectx -\nSwitched to context \"oregon\".\n\n# rename context\n$ kubectx dublin=gke_ahmetb_europe-west1-b_dublin\nContext \"gke_ahmetb_europe-west1-b_dublin\" renamed to \"dublin\".\n\n# change the active namespace on kubectl\n$ kubens kube-system\nContext \"test\" set.\nActive namespace is \"kube-system\".\n\n# go back to the previous namespace\n$ kubens -\nContext \"test\" set.\nActive namespace is \"default\".\n\n# change the active namespace even if it doesn't exist\n$ kubens not-found-namespace --force\nContext \"test\" set.\nActive namespace is \"not-found-namespace\".\n---\n$ kubens not-found-namespace -f\nContext \"test\" set.\nActive namespace is \"not-found-namespace\".\n```\n\nIf you have [`fzf`](https://github.com/junegunn/fzf) installed, you can also\n**interactively** select a context or cluster, or fuzzy-search by typing a few\ncharacters. To learn more, read [interactive mode \u0026rarr;](#interactive-mode)\n\nBoth `kubectx` and `kubens` support \u003ckbd\u003eTab\u003c/kbd\u003e completion on bash/zsh/fish\nshells to help with long context names. You don't have to remember full context\nnames anymore.\n\n-----\n\n## Installation\n\nStable versions of `kubectx` and `kubens` are small bash scripts that you\ncan find in this repository.\n\nStarting with v0.9.0, `kubectx` and `kubens` **are now rewritten in Go**.  They\nshould work the same way (and we'll keep the bash-based implementations around)\nbut the new features will be added to the new Go programs.  Please help us test\nthis new Go implementation by downloading the binaries from the [**Releases page\n\u0026rarr;**](https://github.com/ahmetb/kubectx/releases)\n\n**Installation options:**\n\n- [as kubectl plugins (macOS \u0026 Linux)](#kubectl-plugins-macos-and-linux)\n- [with Homebrew (macOS \u0026 Linux)](#homebrew-macos-and-linux)\n- [with MacPorts (macOS)](#macports-macos)\n- [with apt (Debian)](#apt-debian)\n- [with pacman (Arch Linux)](#pacman-arch-linux)\n- [with Chocolatey (Windows)](#windows-installation-using-chocolatey)\n- [Windows Installation (using Scoop)](#windows-installation-using-scoop)\n- [with winget (Windows)](#windows-installation-using-winget)\n- [manually (macOS \u0026 Linux)](#manual-installation-macos-and-linux)\n\nIf you like to add context/namespace information to your shell prompt (`$PS1`),\nyou can try out [kube-ps1].\n\n[kube-ps1]: https://github.com/jonmosco/kube-ps1\n\n### Kubectl Plugins (macOS and Linux)\n\nYou can install and use the [Krew](https://github.com/kubernetes-sigs/krew/) kubectl\nplugin manager to get `kubectx` and `kubens`.\n\n**Note:** This will not install the shell completion scripts. If you want them,\n*choose another installation method\nor install the scripts [manually](#manual-installation-macos-and-linux).\n\n```sh\nkubectl krew install ctx\nkubectl krew install ns\n```\n\nAfter installing, the tools will be available as `kubectl ctx` and `kubectl ns`.\n\n### Homebrew (macOS and Linux)\n\nIf you use [Homebrew](https://brew.sh/) you can install like this:\n\n```sh\nbrew install kubectx\n```\n\nThis command will set up bash/zsh/fish completion scripts automatically. Make sure you [configure your shell](https://docs.brew.sh/Shell-Completion) to load completions for installed Homebrew formulas.\n\n\n### MacPorts (macOS)\n\nIf you use [MacPorts](https://www.macports.org) you can install like this:\n\n```sh\nsudo port install kubectx\n```\n\n### apt (Debian)\n\n``` bash\nsudo apt install kubectx\n```\nNewer versions might be available on repos like\n[Debian Buster (testing)](https://packages.debian.org/buster/kubectx),\n[Sid (unstable)](https://packages.debian.org/sid/kubectx)\n(_if you are unfamiliar with the Debian release process and how to enable\ntesting/unstable repos, check out the\n[Debian Wiki](https://wiki.debian.org/DebianReleases)_):\n\n\n### pacman (Arch Linux)\n\nAvailable as official Arch Linux package. Install it via:\n\n```bash\nsudo pacman -S kubectx\n```\n\n### Windows Installation (using Chocolatey)\n\nAvailable as packages on [Chocolatey](https://chocolatey.org/why-chocolatey)\n```pwsh\nchoco install kubens kubectx\n```\n\n### Windows Installation (using Scoop)\n\nAvailable as packages on [Scoop](https://scoop.sh/)\n```pwsh\nscoop bucket add main\nscoop install main/kubens main/kubectx\n```\n\n### Windows Installation (using winget)\n\nAvailable as packages on [winget](https://learn.microsoft.com/en-us/windows/package-manager/)\n```pwsh\nwinget install --id ahmetb.kubectx\nwinget install --id ahmetb.kubens\n```\n\n### Manual Installation (macOS and Linux)\n\nSince `kubectx` and `kubens` are written in Bash, you should be able to install\nthem to any POSIX environment that has Bash installed.\n\n- Download the `kubectx`, and `kubens` scripts.\n- Either:\n  - save them all to somewhere in your `PATH`,\n  - or save them to a directory, then create symlinks to `kubectx`/`kubens` from\n    somewhere in your `PATH`, like `/usr/local/bin`\n- Make `kubectx` and `kubens` executable (`chmod +x ...`)\n\nExample installation steps:\n\n``` bash\nsudo git clone https://github.com/ahmetb/kubectx /opt/kubectx\nsudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx\nsudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens\n```\n\nIf you also want to have shell completions, pick an installation method for the\n[completion scripts](completion/) that fits your system best: [`zsh` with\n`antibody`](#completion-scripts-for-zsh-with-antibody), [plain\n`zsh`](#completion-scripts-for-plain-zsh),\n[`bash`](#completion-scripts-for-bash) or\n[`fish`](#completion-scripts-for-fish).\n\n#### Completion scripts for `zsh` with [antibody](https://getantibody.github.io)\n\nAdd this line to your [Plugins File](https://getantibody.github.io/usage/) (e.g.\n`~/.zsh_plugins.txt`):\n\n```\nahmetb/kubectx path:completion kind:fpath\n```\n\nDepending on your setup, you might or might not need to call `compinit` or\n`autoload -U compinit \u0026\u0026 compinit` in your `~/.zshrc` after you load the Plugins\nfile. If you use [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh), load the\ncompletions before you load `oh-my-zsh` because `oh-my-zsh` will call\n`compinit`. \n\n#### Completion scripts for plain `zsh`\n\nThe completion scripts have to be in a path that belongs to `$fpath`. Either\nlink or copy them to an existing folder.\n\nExample with [`oh-my-zsh`](https://github.com/ohmyzsh/ohmyzsh):\n\n```bash\nmkdir -p ~/.oh-my-zsh/custom/completions\nchmod -R 755 ~/.oh-my-zsh/custom/completions\nln -s /opt/kubectx/completion/_kubectx.zsh ~/.oh-my-zsh/custom/completions/_kubectx.zsh\nln -s /opt/kubectx/completion/_kubens.zsh ~/.oh-my-zsh/custom/completions/_kubens.zsh\necho \"fpath=($ZSH/custom/completions $fpath)\" \u003e\u003e ~/.zshrc\n```\n\nIf completion doesn't work, add `autoload -U compinit \u0026\u0026 compinit` to your\n`.zshrc` (similar to\n[`zsh-completions`](https://github.com/zsh-users/zsh-completions/blob/master/README.md#oh-my-zsh)).\n\nIf you are not using [`oh-my-zsh`](https://github.com/ohmyzsh/ohmyzsh), you\ncould link to `/usr/share/zsh/functions/Completion` (might require sudo),\ndepending on the `$fpath` of your zsh installation.\n\nIn case of errors, calling `compaudit` might help.\n\n#### Completion scripts for `bash`\n\n```bash\ngit clone https://github.com/ahmetb/kubectx.git ~/.kubectx\nCOMPDIR=$(pkg-config --variable=completionsdir bash-completion)\nln -sf ~/.kubectx/completion/kubens.bash $COMPDIR/kubens\nln -sf ~/.kubectx/completion/kubectx.bash $COMPDIR/kubectx\ncat \u003c\u003c EOF \u003e\u003e ~/.bashrc\n\n\n#kubectx and kubens\nexport PATH=~/.kubectx:\\$PATH\nEOF\n```\n\n#### Completion scripts for `fish`\n\n```fish\nmkdir -p ~/.config/fish/completions\nln -s /opt/kubectx/completion/kubectx.fish ~/.config/fish/completions/\nln -s /opt/kubectx/completion/kubens.fish ~/.config/fish/completions/\n```\n\n-----\n\n### Interactive mode\n\nIf you want `kubectx` and `kubens` commands to present you an interactive menu\nwith fuzzy searching, you just need to [install\n`fzf`](https://github.com/junegunn/fzf) in your `$PATH`.\n\n![kubectx interactive search with fzf](img/kubectx-interactive.gif)\n\nIf you have `fzf` installed, but want to opt out of using this feature, set the\nenvironment variable `KUBECTX_IGNORE_FZF=1`.\n\nIf you want to keep `fzf` interactive mode but need the default behavior of the\ncommand, you can do it by piping the output to another command (e.g. `kubectx |\ncat `).\n\n-----\n\n### Customizing colors\n\nIf you like to customize the colors indicating the current namespace or context,\nset the environment variables `KUBECTX_CURRENT_FGCOLOR` and\n`KUBECTX_CURRENT_BGCOLOR` (refer color codes\n[here](https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/)):\n\n```sh\nexport KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6) # blue text\nexport KUBECTX_CURRENT_BGCOLOR=$(tput setab 7) # white background\n```\n\nColors in the output can be disabled by setting the\n[`NO_COLOR`](https://no-color.org/) environment variable.\n\n-----\n\nIf you liked `kubectx`, you may like my\n[`kubectl-aliases`](https://github.com/ahmetb/kubectl-aliases) project, too. I\nrecommend pairing kubectx and kubens with [fzf](#interactive-mode) and\n[kube-ps1].\n\n#### Stargazers over time\n\n[![Stargazers over time](https://starchart.cc/ahmetb/kubectx.svg)](https://starchart.cc/ahmetb/kubectx)\n![Google Analytics](https://ga-beacon.appspot.com/UA-2609286-17/kubectx/README?pixel) \u003c!-- TODO broken since Aug 2021 as igrigorik left Google --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fkubectx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmetb%2Fkubectx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmetb%2Fkubectx/lists"}