### Install kubectx and kubens using Scoop Source: https://github.com/ahmetb/kubectx/blob/master/README.md Install `kubectx` and `kubens` on Windows using the Scoop package manager. This involves adding the main bucket and then installing the individual packages. ```sh scoop bucket add main && scoop install main/kubens main/kubectx ``` -------------------------------- ### Install kubectx and kubens using winget Source: https://github.com/ahmetb/kubectx/blob/master/README.md Install `kubectx` and `kubens` on Windows using the `winget` package manager. This command uses the package manager's IDs to install the tools. ```sh winget install --id ahmetb.kubectx && winget install --id ahmetb.kubens ``` -------------------------------- ### Install Kubectx for Fish Shell Source: https://github.com/ahmetb/kubectx/blob/master/README.md Creates a directory for fish completions and links the kubectx and kubens completion files. ```fish mkdir -p ~/.config/fish/completions ln -s /opt/kubectx/completion/kubectx.fish ~/.config/fish/completions/ ln -s /opt/kubectx/completion/kubens.fish ~/.config/fish/completions/ ``` -------------------------------- ### Install kubectx as a kubectl plugin using Krew Source: https://github.com/ahmetb/kubectx/blob/master/README.md Install `kubectx` (as `ctx`) and `kubens` (as `ns`) as kubectl plugins using Krew. This method integrates the tools directly into kubectl commands. ```sh kubectl krew install ctx && kubectl krew install ns ``` -------------------------------- ### Install kubectx using Homebrew Source: https://github.com/ahmetb/kubectx/blob/master/README.md Install `kubectx` on macOS or Linux using the Homebrew package manager. This is a common and convenient method for managing the tool. ```sh brew install kubectx ``` -------------------------------- ### Install kubectx and kubens using Chocolatey Source: https://github.com/ahmetb/kubectx/blob/master/README.md Install both `kubectx` and `kubens` on Windows using the Chocolatey package manager. This command ensures both tools are available for use. ```sh choco install kubens kubectx ``` -------------------------------- ### Install Kubectx for Bash Shell Source: https://github.com/ahmetb/kubectx/blob/master/README.md Clones the repository, sets up bash completion for kubens and kubectx, and adds kubectx to the PATH in .bashrc. ```bash git clone https://github.com/ahmetb/kubectx.git ~/.kubectx COMPDIR=$(pkg-config --variable=completionsdir bash-completion) ln -sf ~/.kubectx/completion/kubens.bash $COMPDIR/kubens ln -sf ~/.kubectx/completion/kubectx.bash $COMPDIR/kubectx cat << EOF >> ~/.bashrc #kubectx and kubens export PATH=~/.kubectx:$PATH EOF ``` -------------------------------- ### Start a read-only shell for a context Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubectx -r` to start a shell session where all write operations to the cluster are blocked. This is ideal for exploratory tasks or when you only need to view cluster state. ```sh kubectx -r minikube ``` -------------------------------- ### Start an isolated shell for a context Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubectx -s` to launch a new shell session that is restricted to a single specified context. This helps in preventing accidental operations on the wrong cluster. ```sh kubectx -s minikube ``` -------------------------------- ### Switch to the previous context Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubectx -` to quickly revert to the context you were using before the last switch. This is useful for toggling between two frequently used contexts. ```sh kubectx - Switched to context "oregon". ``` -------------------------------- ### Configure zsh completion manually with Oh My Zsh Source: https://github.com/ahmetb/kubectx/blob/master/README.md Manually set up `kubectx` and `kubens` shell completion for zsh when using Oh My Zsh. This involves creating symbolic links and updating your `.zshrc`. ```sh mkdir -p ~/.oh-my-zsh/custom/completions chmod -R 755 ~/.oh-my-zsh/custom/completions ln -s /opt/kubectx/completion/_kubectx.zsh ~/.oh-my-zsh/custom/completions/_kubectx.zsh ln -s /opt/kubectx/completion/_kubens.zsh ~/.oh-my-zsh/custom/completions/_kubens.zsh echo "fpath=($ZSH/custom/completions $fpath)" >> ~/.zshrc ``` -------------------------------- ### Revert to the previous namespace Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubens -` to quickly switch back to the namespace that was active before the last `kubens` command. This is useful for toggling between two common namespaces. ```sh kubens - Context "test" set. Active namespace is "default". ``` -------------------------------- ### Configure zsh completion with Antibody Source: https://github.com/ahmetb/kubectx/blob/master/README.md Add `kubectx` shell completion for zsh using the Antibody plugin manager. This involves adding a specific line to your plugin file. ```sh ahmetb/kubectx path:completion kind:fpath ``` -------------------------------- ### Customize Kubectx Colors Source: https://github.com/ahmetb/kubectx/blob/master/README.md Sets environment variables to customize the foreground and background colors for the current namespace or context. Uses tput for color codes. ```sh export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6) # blue text export KUBECTX_CURRENT_BGCOLOR=$(tput setab 7) # white background ``` -------------------------------- ### Switch to a specific context Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubectx` to switch to a different cluster context defined in your kubeconfig. This command is straightforward and immediately applies the context change. ```sh kubectx minikube Switched to context "minikube". ``` -------------------------------- ### Change namespace, even if it doesn't exist Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubens -f` to set the active namespace to one that may not currently exist in the cluster. This can be useful for pre-configuring a namespace for future use. ```sh kubens namespace-404 -f Context "test" set. Active namespace is "namespace-404". ``` -------------------------------- ### Rename a context Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubectx` with the `old_name=new_name` format to rename an existing context in your kubeconfig. This helps in maintaining organized and descriptive context names. ```sh kubectx dublin=gke_ahmetb_europe-west1-b_dublin Context "gke_ahmetb_europe-west1-b_dublin" renamed to "dublin". ``` -------------------------------- ### Change the active namespace Source: https://github.com/ahmetb/kubectx/blob/master/README.md Use `kubens` to change the active namespace for subsequent kubectl commands. This command updates the current context's namespace setting. ```sh kubens kube-system Context "test" set. Active namespace is "kube-system". ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.