A simple kubectl context switcher cli tool
Project description
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:
-
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.- Installation guide: kubectl official documentation
-
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
-
Clone the repository:
git clone https://github.com/yourusername/contswi.git cd contswi
-
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
Usage
Once installed, you can use the contswi
tool to interactively switch Kubernetes contexts.
Run the tool
contswi
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
-
Running
contswi
will present a list of your Kubernetes contexts:dev-cluster > prod-cluster < staging-cluster
-
Use the arrow keys to navigate through the contexts and press Enter to switch.
-
The tool will execute the equivalent of:
kubectl config use-context <selected_context>
-
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.
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
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file contswi-0.1.5.tar.gz
.
File metadata
- Download URL: contswi-0.1.5.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5504b933c2bc4f4d51759cbaa0c869a1862696f9198db65de2c9e22d153807c8 |
|
MD5 | 471b9c9bbe56d7fdeeae98b8368368b9 |
|
BLAKE2b-256 | a77e2610af4752ae9e3b1c0e7867f42fd9cda028b11b2d924b146e7a6e1f5480 |
File details
Details for the file contswi-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: contswi-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71a9c3930db616d3b2cec42d545a55e319ab57918bb769455d001a2685a71f42 |
|
MD5 | 27c2fddb1286b8f02dcecd9d45da4dff |
|
BLAKE2b-256 | cc32841f8a871cfdb7842294228bdd18080a300f4a614e59c06a67df83049976 |