Skip to main content

contswi - Kubernetes Context Switcher

contswi is a simple but effective command-line tool designed for Linux environments to quickly switch between different Kubernetes contexts. By leveraging kubectl, this tool allows users to select and change their active context using an intuitive menu-driven interface, navigable with arrow keys.

Features

  • Quickly view all available Kubernetes contexts.
  • Highlight the current active context.
  • Easily switch between contexts using an interactive, arrow-key driven menu.
  • Clean, responsive, and simple interface that fits into any Kubernetes workflow.

Requirements

Before using contswi, ensure you have the following set up:

  1. kubectl: The Kubernetes command-line tool must be installed and properly configured on your system. This application interacts directly with kubectl to retrieve and set contexts.

  2. Pre-configured Kubernetes Contexts: You must have one or more Kubernetes contexts already set up in your kubeconfig. If you don't have any contexts configured, refer to the Kubernetes context documentation to set them up.

Installation

You can install the contswi tool in two ways: directly from the source code or via pip.

1. Installing from Source

  1. Clone the repository:

    git clone https://github.com/yourusername/contswi.git
    cd contswi
    
  2. Install the tool:

    After cloning the repository, you can install the tool locally with pip:

    pip install .
    

2. Installing via pip

To install the tool directly from PyPI, simply run:

pip install contswi

pip install contswi

Usage

Once installed, you can use the contswi tool to interactively switch Kubernetes contexts.

Run the tool

contswi

contswi how to use

Key Bindings

  • Up Arrow (↑): Move the selection upwards.
  • Down Arrow (↓): Move the selection downwards.
  • Enter: Select the highlighted context and switch to it.
  • Ctrl+C: Exit the program at any time.

Example

  1. Running contswi will present a list of your Kubernetes contexts:

      dev-cluster  
    > prod-cluster <  
      staging-cluster  
    
  2. Use the arrow keys to navigate through the contexts and press Enter to switch.

  3. The tool will execute the equivalent of:

    kubectl config use-context <selected_context>
    
  4. You will see the selected context become the active one.

Using with k9s

We love k9s—it’s one of the best, if not the best, Kubernetes IDE out there, and we thank Fernand Galiana for creating this fantastic tool. To make your experience even smoother, you can integrate contswi with k9s to ensure that every time you launch k9s, you first select your Kubernetes context conveniently.

To do this, add the following alias to your .bashrc file:

alias k9="contswi && k9s"

Then, reload your shell configuration by running:

source ~/.bashrc

This setup ensures that each time you run k9, you are prompted to select the desired Kubernetes context through contswi before launching k9s. This allows you to comfortably switch between clusters and environments, enhancing your productivity when managing Kubernetes resources.

For more information on k9s, check out the official repository.

contswi with k9s

Error Handling

If you encounter any errors or issues with the program (e.g., no configured contexts), the tool will handle it gracefully, providing helpful error messages.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to submit issues, feature requests, or pull requests to improve the functionality of this tool. Contributions are always welcome!


Author

Gabor Puskas
GitHub
LinkedIn


contswi is designed to make Kubernetes context management fast and simple, enhancing the experience for developers and DevOps engineers working across multiple clusters and environments.

Metadata

Release files for contswi 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contswi 0.1.5
File Size Uploaded
contswi-0.1.5.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contswi 0.1.5
File Interpreter ABI Platform
contswi-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 10.4 kB

Release files / contswi-0.1.5.tar.gz

Download URL contswi-0.1.5.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5504b933c2bc4f4d51759cbaa0c869a1862696f9198db65de2c9e22d153807c8
BLAKE2b-256 checksum
How to use checksums
a77e2610af4752ae9e3b1c0e7867f42fd9cda028b11b2d924b146e7a6e1f5480
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release files / contswi-0.1.5-py3-none-any.whl

Download URL contswi-0.1.5-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
71a9c3930db616d3b2cec42d545a55e319ab57918bb769455d001a2685a71f42
BLAKE2b-256 checksum
How to use checksums
cc32841f8a871cfdb7842294228bdd18080a300f4a614e59c06a67df83049976
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.17

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page