The ks CLI is a command line tool for managing multiple Kubernetes configurations. It allows you to register, manage, and activate Kubernetes clusters, as well as integrate with Zsh and Oh-My-Zsh.
It runs on Linux, macOS, and Windows. On Windows it uses %USERPROFILE% for the home directory, spawns the shell defined by ComSpec (defaulting to cmd.exe), defaults to notepad as the editor, and copies the default kubeconfig when symlinks aren't permitted.
Install the ks CLI using go install:
go install github.com/giancarlopro/ks@latestThe ks CLI provides the following commands:
ks: Shows a list of clusters that you can select to enter an interactive shell with the correct environment variables.ks <cluster-name>: Activate a cluster directly, without opening the selector, entering an interactive shell with the correct environment variables.ks add <cluster-name>: Register a new Kubernetes cluster with the given name and open the default editor for the user to set the content of the file.ks list: List all registered Kubernetes clusters.ks get <cluster-name>: Get the details of a specific Kubernetes cluster.ks edit <cluster-name>: Open the default editor for the user to edit the cluster configuration.ks delete <cluster-name>: Delete a registered Kubernetes cluster.ks activate <cluster-name>: Activate a Kubernetes cluster, setting theKUBECONFIGenvironment variable to point to the selected cluster's configuration file.ks set-default <cluster-name>: Set a default Kubernetes cluster, creating a symbolic link to the defaultkubectlconfig file.ks zsh-integration: Set up Zsh and Oh-My-Zsh integration to read the.ksconfigfile in a folder and set the cluster accordingly.ks shell-init [shell]: Print a set of handykubectlaliases/functions for the given shell (bash,zsh,powershell, orcmd). The shell is auto-detected when omitted.
ks shell-init emits a curated set of kubectl shortcuts for your shell:
| Alias | Expands to |
|---|---|
kg |
kubectl get |
kd |
kubectl describe |
krrd |
kubectl rollout restart deployment |
krrs |
kubectl rollout restart statefulset |
ktn |
kubectl top node |
kdn |
kubectl describe node |
kl |
kubectl logs |
klf |
kubectl logs -f |
cns [namespace] |
Switch the current namespace (falls back to an fzf picker when no namespace is given) |
To load them every session, add the appropriate line to your shell startup file:
# bash (~/.bashrc)
eval "$(ks shell-init bash)"
# zsh (~/.zshrc)
eval "$(ks shell-init zsh)"# PowerShell ($PROFILE)
ks shell-init powershell | Out-String | Invoke-Expression:: cmd.exe — write the doskey macros and load them on startup via AutoRun
ks shell-init cmd > "%USERPROFILE%\ks-aliases.cmd"
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /d "%USERPROFILE%\ks-aliases.cmd" /fOn
cmd.exe,cnsrequires an explicit namespace argument, sincedoskeycannot run thefzfpicker.
To set up Zsh and Oh-My-Zsh integration, follow these steps:
- Create a
.ksconfigfile in the project directory to specify the desired Kubernetes cluster:
echo "cluster-name" > .ksconfig- Add the following lines to your
.zshrcfile to enable the integration:
ks zsh-integration- Restart your terminal or source the
.zshrcfile:
source ~/.zshrcNow, when you navigate to a directory with a .ksconfig file, the KUBECONFIG environment variable will be automatically set to the specified cluster's configuration file.
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
This project is licensed under the MIT License. See the LICENSE file for details.