Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/weibeld/kubectl-ctx

A kubectl plugin for interactively changing the kubeconfig context
https://github.com/weibeld/kubectl-ctx

kubectl kubectl-plugins kubernetes

Last synced: 2 months ago
JSON representation

A kubectl plugin for interactively changing the kubeconfig context

Awesome Lists containing this project

README

        

# kubectl ctx

A kubectl [plugin](https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/) for interactively changing your *kubeconfig* context.

![Demo](img/demo.gif)

This makes it easier to work with multiple clusters from the same machine.

Also see [kubectl-ns](https://github.com/weibeld/kubectl-ns) for switching between namespaces.

## Installation

To install the plugin, download the `kubectl-ctx` file and save it in any directory that is in your `PATH`:

~~~bash
curl -O https://raw.githubusercontent.com/weibeld/kubectl-ctx/master/kubectl-ctx
~~~

Then, make the `kubectl-ctx` file executable:

~~~bash
chmod +x kubectl-ctx
~~~

Now, you can verify that the plugin is correctly installed by running the following command:

~~~bash
kubectl plugin list
~~~~

This lists all the plugins that `kubectl` detected, and the `kubectl-ctx` plugin should now be listed there.

To uninstall the plugin, simply delete the `kubectl-ctx` file.

## Usage

Change the current context:

~~~bash
kubectl ctx
~~~

List all contexts:

~~~bash
kubectl ctx -l
~~~

## How It Works

When you run `kubectl ctx`, the plugin changes the `current-context` element of your [*kubeconfig*](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) configuration:

![How it works](img/how-it-works.png)

Note that this includes a physical change to one of your *kubeconfig* files (the default *kubeconfig* file is `~/.kube/config`, but you can have multiple *kubeconfig* files by by listing them in the [`KUBECONFIG`](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable) environment variable).

When you run `kubectl ctx -l`, the plugin displays the names of all the contexts in your *kubeconfig* configuration.

## Dependencies

The plugin depends on the [fzf](https://github.com/junegunn/fzf) command being available on your system.

You can install fzf as follows:

- Homebrew (macOS) and Linuxbrew (Linux):
~~~bash
brew install fzf
~~~
- From source (macOS and Linux):
~~~bash
git clone https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install
~~~
- For further installation options, see [here](https://github.com/junegunn/fzf#installation)