Skip to content
/ kubex Public

A lightweight CLI tool for managing Kubernetes contexts

License

Notifications You must be signed in to change notification settings

drone076/kubex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubex

Build Status

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.

Features

  • 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.

Installation

1. Quick Installation via "curl-to-bash"

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.


2. Download Precompiled Binaries

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.


3. Build from Source

If you prefer to build kubex from source, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourusername/kubex.git
    cd kubex
  2. Build the binary:

    go build -o kubex
  3. Move the binary to a directory in your PATH:

    sudo mv kubex /usr/local/bin/

Usage

List Contexts

View all available Kubernetes contexts:

kubex list

Example output:

Available contexts:
- minikube
- gke_my-cluster (active)
- docker-desktop

Switch Context

Switch to a specific context:

kubex use <context-name>

Example:

kubex use minikube

Output:

Switched to context: minikube

Show Current Context

Display the currently active context:

kubex current

Example output:

Current context: minikube

Autocompletion

kubex supports shell autocompletion for Bash, Zsh, and Fish. Follow the instructions below to enable it.

Bash

Add the following line to your ~/.bashrc or ~/.bash_profile:

source <(kubex completion bash)

Reload the shell:

source ~/.bashrc

Zsh

Add the following line to your ~/.zshrc:

source <(kubex completion zsh)

Reload the shell:

source ~/.zshrc

Fish

Add the following line to your Fish configuration file (~/.config/fish/config.fish):

kubex completion fish | source

Building from Source

To build kubex for multiple platforms, use the following commands:

Build for Linux

GOOS=linux GOARCH=amd64 go build -o kubex-linux

Build for macOS

GOOS=darwin GOARCH=amd64 go build -o kubex-macos

Automated Build Script

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

Contributing

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.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Commit your changes (git commit -m "Add some feature").
  4. Push to the branch (git push origin feature/your-feature).
  5. Open a pull request.

License

This project is licensed under the GNU General Public License.


Acknowledgments

  • Inspired by kubectx.
  • Built using the Go programming language and the cobra library.

Support

If you encounter any issues or have questions, feel free to open an issue on GitHub or reach out to the maintainers.

Happy Kubing! 🚀