Skip to content

michizubi-SRF/ktx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ktx - Kubernetes Context Switcher

A simple and fast CLI tool for switching between Kubernetes contexts with an interactive interface.

Features

  • 🚀 Fast and lightweight
  • 🎯 Interactive context selection with arrow key navigation
  • ⌨️ Type-to-filter contexts in real-time
  • 🔄 Direct context switching via argument
  • 🔍 Fuzzy matching for context names
  • 📋 List all available contexts
  • 🎨 Colored output with context details
  • ✅ Built with promptui for smooth interactive experience

Quick Start

# Interactive mode - select context with arrow keys
ktx

# Direct switch - provide context name
ktx production

# List all contexts
ktx list

Installation

Local Build

git clone https://github.com/michizubi-SRF/ktx
cd ktx
go build -o ktx
sudo mv ktx /usr/local/bin/

Usage

Interactive Mode

Simply run ktx to launch the interactive context selector:

ktx

Features in interactive mode:

  • ↑/↓ Arrow keys: Navigate through contexts
  • Type to filter: Start typing to filter contexts in real-time
  • Enter: Select and switch to the highlighted context
  • Ctrl+C: Exit without changing context

The tool shows context details including cluster, namespace, and user after selection.

Direct Switch

Provide the context name as an argument to switch directly:

ktx production-cluster

List Contexts

List all available contexts:

ktx list
# or
ktx ls

Fuzzy Matching

The tool supports fuzzy matching. If you provide a partial name, it will:

  • Switch automatically if there's only one match
  • Show suggestions if there are multiple matches
ktx prod  # Will switch to 'production-cluster' if it's the only match

Help

Show help information:

ktx help
# or
ktx -h

Configuration

The tool uses your standard kubeconfig file:

  • Default: ~/.kube/config
  • Custom: Set the KUBECONFIG environment variable
export KUBECONFIG=/path/to/your/kubeconfig
ktx

How It Works

ktx provides an interactive terminal UI for switching Kubernetes contexts:

  1. Interactive Mode: Uses promptui to provide a smooth selection experience with arrow key navigation and real-time filtering
  2. Context Management: Reads your kubeconfig file using the Kubernetes client-go library
  3. Switching: Updates the current-context field in your kubeconfig when you select a new context
  4. Context Details: Shows cluster, namespace, and user information for the selected context

Dependencies

Requirements

  • Go 1.21 or higher
  • Access to a kubeconfig file

Development

# Clone the repository
git clone https://github.com/michizubi-SRF/ktx
cd ktx

# Install dependencies
go mod download

# Run locally
go run main.go

# Build
go build -o ktx

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages