Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbueringer/kubectx
Faster way to switch between kubeconfigs, clusters and namespaces in kubectl
https://github.com/sbueringer/kubectx
kcfg kubectl kubectx kubens
Last synced: 3 months ago
JSON representation
Faster way to switch between kubeconfigs, clusters and namespaces in kubectl
- Host: GitHub
- URL: https://github.com/sbueringer/kubectx
- Owner: sbueringer
- License: apache-2.0
- Created: 2018-07-07T09:45:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-25T13:48:51.000Z (over 3 years ago)
- Last Synced: 2024-06-20T03:37:20.895Z (7 months ago)
- Topics: kcfg, kubectl, kubectx, kubens
- Language: Go
- Homepage:
- Size: 8.32 MB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kubectx
Command line utility to manage the current environment consisting of kubeconfig, context and namespace. The environment is stored in `~/.kube/kubectx.json` file. The environment can be stored per terminal, if the environment variable `TERMINAL_ID` exists. This variable can be created e.g. in your `~/.zshrc` with:
````
export TERMINAL_ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
````# Installation
## Binary
Go to the [releases](https://github.com/sbueringer/kubectx/releases) page and download the Linux or Windows version. Put the binary to somewhere you want (on UNIX-ish systems, /usr/local/bin or the like). Make sure it has execution bit set. If you want, you can shortcuts to `kcfg`, `kctx` and `kns`, e.g.:
````
function kcfg() { kubectx config "$@" }
function kctx() { kubectx context "$@" }
function kns() { kubectx namespace "$@" }
````
## Auto completionAuto completion scripts are provided for [zsh](./completion). They can be added or symlinked, e.g. to `/usr/share/zsh/site-functions`.
# Basic usage
kubectx is build with Cobra so the CLI is build in a familiar way (Cobra is also used in Docker and Kubernetes).
To print a description what kubectx can do, just execute:
````
$ kubectx
kubectx manages kubectl context incl. kubeconfig, context and namespaceUsage:
kubectx [flags]
kubectx [command]Available Commands:
completion Generates bash completion scripts
config Gets and sets the current config
context Gets and sets the current context
help Help about any command
namespace Gets and sets the current namespaceFlags:
-h, --help help for kubectxUse "kubectx [command] --help" for more information about a command.
````# Example usage with kubectl
Sourced e.g. via `.zshrc`:
````
function k(){
~/bin/kubectl --kubeconfig $(kcfg) --context $(kctx) --namespace $(kns) "$@"
}
alias kubectl='k 'if command -v kubectl > /dev/null 2>&1; then
source <(kubectl completion zsh)
fi
````
This can also be used in your favorite prompt theme, e.g. see [prompt_sbueringer_setup](https://github.com/sbueringer/prezto/blob/master/modules/prompt/functions/prompt_sbueringer_setup#L99-L104)