kubex
is a lightweight CLI tool for managing Kubernetes contexts. It simplifies switching between Kubernetes contexts and viewing the current context. Think of it as a stripped-down version of kubectx
, designed to be simple, fast, and cross-platform.
- List Contexts: View all available Kubernetes contexts.
- Switch Contexts: Switch to a specific context by name.
- Show Current Context: Display the currently active context.
- Autocompletion: Supports shell autocompletion for commands and context names (Bash, Zsh, Fish).
- Cross-Platform: Works on Linux, macOS, and optionally Windows.
You can install kubex
with a single command using the following "curl-to-bash" script:
curl -fsSL https://raw.githubusercontent.com/yourusername/kubex/main/install.sh | bash
Note: Always inspect the script before running it:
curl -fsSL https://raw.githubusercontent.com/yourusername/kubex/main/install.sh | less
The script will automatically detect your operating system and architecture, download the appropriate binary, and install it to /usr/local/bin
.
Download the appropriate binary for your operating system:
-
Linux:
wget https://example.com/kubex-linux -O kubex chmod +x kubex sudo mv kubex /usr/local/bin/
-
macOS:
curl -L https://example.com/kubex-macos -o kubex chmod +x kubex sudo mv kubex /usr/local/bin/
Replace
https://example.com/
with the actual URL where you host the binaries.
If you prefer to build kubex
from source, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/kubex.git cd kubex
-
Build the binary:
go build -o kubex
-
Move the binary to a directory in your
PATH
:sudo mv kubex /usr/local/bin/
View all available Kubernetes contexts:
kubex list
Example output:
Available contexts:
- minikube
- gke_my-cluster (active)
- docker-desktop
Switch to a specific context:
kubex use <context-name>
Example:
kubex use minikube
Output:
Switched to context: minikube
Display the currently active context:
kubex current
Example output:
Current context: minikube
kubex
supports shell autocompletion for Bash, Zsh, and Fish. Follow the instructions below to enable it.
Add the following line to your ~/.bashrc
or ~/.bash_profile
:
source <(kubex completion bash)
Reload the shell:
source ~/.bashrc
Add the following line to your ~/.zshrc
:
source <(kubex completion zsh)
Reload the shell:
source ~/.zshrc
Add the following line to your Fish configuration file (~/.config/fish/config.fish
):
kubex completion fish | source
To build kubex
for multiple platforms, use the following commands:
GOOS=linux GOARCH=amd64 go build -o kubex-linux
GOOS=darwin GOARCH=amd64 go build -o kubex-macos
Save the following script as build.sh
and run it to generate binaries for both platforms:
#!/bin/bash
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o kubex-linux
# Build for macOS
GOOS=darwin GOARCH=amd64 go build -o kubex-macos
echo "Binaries built: kubex-linux, kubex-macos"
Make it executable and run:
chmod +x build.sh
./build.sh
We welcome contributions! If you find a bug or have an idea for a new feature, please open an issue or submit a pull request.
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Commit your changes (
git commit -m "Add some feature"
). - Push to the branch (
git push origin feature/your-feature
). - Open a pull request.
This project is licensed under the GNU General Public License.
If you encounter any issues or have questions, feel free to open an issue on GitHub or reach out to the maintainers.
Happy Kubing! 🚀