Installation
Installation
Section titled “Installation”The kswitch installation consists of a kubectl-switch binary and a shell function that must be sourced into your shell.
NOTE: Always invoke kswitch via the shell function (kswitch), not the binary directly (kubectl-switch).
The shell function is required to export KUBECONFIG into your current shell session.
Option 1 - Homebrew (macOS)
Section titled “Option 1 - Homebrew (macOS)”brew tap MichaelSp/kswitchbrew trust --cask michaelsp/kswitch/kubectl-switchbrew install kubectl-switchNext, follow required: source the shell function.
Option 2 - Github releases
Section titled “Option 2 - Github releases”Download the kubectl-switch binary:
curl -L -o /usr/local/bin/kubectl-switch "https://github.com/MichaelSp/kswitch/releases/latest/download/kubectl-switch_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')"chmod +x /usr/local/bin/kubectl-switchIf you are using Windows, go to the release page and download the Windows binary: https://github.com/MichaelSp/kswitch/releases/
Copy it to a folder in your PATH. To add a folder to the path for the current PowerShell session: $env:Path += ';C:\myfolder'
Next, follow required: source the shell function.
Option 3 - From source
Section titled “Option 3 - From source”go get github.com/MichaelSp/kswitchFrom the repository root run make build-kswitch.
This builds the binaries to /hack/switch/.
Copy the binary for your OS/architecture to e.g. /usr/local/bin/kubectl-switch.
Next, follow required: source the shell function.
Required: Source the shell function
Section titled “Required: Source the shell function”The kubectl-switch init command generates both the kswitch shell function and the tab-completion script.
Source its output in your shell rc file so the kswitch command is available in every new shell.
echo 'source <(kubectl-switch init bash)' >> ~/.bashrc
# optionally use alias `s` instead of `kswitch`echo 'alias s=kswitch' >> ~/.bashrcecho 'complete -o default -F __start_kswitch s' >> ~/.bashrcecho 'source <(kubectl-switch init zsh)' >> ~/.zshrc
# optionally use alias `s` instead of `kswitch`echo 'alias s=kswitch' >> ~/.zshrcecho 'kubectl-switch init fish | source' >> ~/.config/fish/config.fish
# optionally use alias `s` instead of `kswitch`echo 'function s --wraps kswitch; kswitch $argv; end' >> ~/.config/fish/config.fishPowerShell
Section titled “PowerShell”kubectl-switch.exe init powershell >> $PROFILE
# add this for autocomplete to workecho 'Register-ArgumentCompleter -CommandName ''kswitch'' -ScriptBlock $__kswitchCompleterBlock' >> $PROFILE
# optionally use alias `s` instead of `kswitch`echo "Set-Alias -Name s -Value kswitch" >> $PROFILEecho 'Register-ArgumentCompleter -CommandName ''s'' -ScriptBlock $__kswitchCompleterBlock' >> $PROFILE
# re-source your profile. $PROFILECheck that it works
Section titled “Check that it works”Run kswitch (or s if you set the alias) from any terminal.
If the command is not found, open a new terminal or re-source your rc file (.zshrc, .bashrc, …).
That should display the contexts the tool can find with the default configuration.
If you get Error: you need to point kswitch to a kubeconfig file or do not see all desired contexts,
follow kubeconfig stores for configuration.
