https://github.com/mumoshu/config-registry
Switch between kubeconfigs and avoid unintentional operation on your production clusters.
https://github.com/mumoshu/config-registry
krew krew-plugin kubernetes
Last synced: 12 months ago
JSON representation
Switch between kubeconfigs and avoid unintentional operation on your production clusters.
- Host: GitHub
- URL: https://github.com/mumoshu/config-registry
- Owner: mumoshu
- License: apache-2.0
- Created: 2020-10-09T00:53:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-01-09T10:16:44.000Z (over 4 years ago)
- Last Synced: 2024-10-13T13:05:45.218Z (over 1 year ago)
- Topics: krew, krew-plugin, kubernetes
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 34
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# config-registry


[](https://github.com/mumoshu/config-registry/actions?query=workflow%3A"Test")
`config-registry` is a utility to manage and switch between kubeconfigs.
Use this to **avoid unintentional operation on your production clusters**, while easing the management of multiple clusters.
```
Usage:
config-registry [flags]
config-registry [command]
Available Commands:
cp copy config OLD to NEW
current show the current config name
help Help about any command
import import existing kubeconfig at PATH as NAME
init initialize kubeconf
locate print the path to config NAME
ls list the configs
mv rename config OLD to NEW
rm delete config NAME
use switch to config NAME
Flags:
-h, --help help for ./kubeconf
Use "config-registry [command] --help" for more information about a command.
```
### Usage
```sh
$ config-registry init
✔ Config default created.
$ config-registry cp . custom1
Copied config "default" to "custom1".
$ $EDITOR "$(config-registry locate custom1)"
$ config-registry mv custom1 prod
Renamed config "custom1" to "prod".
$ config-registry ls
default
prod
$ config-registry use prod
Switched to config "prod".
$ config-registry use -
Switched to config "default".
$ config-registry locate prod
$HOME/.kube/kubeconf/registry/prod
```
Switching to the production config by using `config-registry use prod` is strongly NOT RECOMMEND.
That's because doing so may result in you running a disruptive operation on the production cluster without noticing the current config is production.
Instead, use `config-registry locate prod`.
With that you can grab the kubeconfig path without switching,
so that you will never end up running unexpected operations in production:
```
# Avoid unintentional operation on prod by using `config-registry locate`
$ KUBECONFIG=$(config-registry locate prod) kubectl version
```
-----
## Installation
There two installation options:
- As kubectl plugins (macOS/Linux)
- Manual installation
### Kubectl Plugins (macOS and Linux)
You can install and use [Krew](https://github.com/kubernetes-sigs/krew/) kubectl
plugin manager to get `config-registry`.
```sh
kubectl krew install config-registry
```
After installing, the plugin will be available as `kubectl config-registry`.
-----
### Manual installation
----
## Interactive mode
If you want `config-registry` command to present you an interactive menu
with fuzzy searching, you just need to [install
`fzf`](https://github.com/junegunn/fzf) in your PATH.
If you have `fzf` installed, but want to opt out of using this feature, set the environment variable `CONFIG_REGISTRY_IGNORE_FZF=1`.
If you want to keep `fzf` interactive mode but need the default behavior of the command, you can do it using Unix composability:
```
config-registry | cat
```
-----
### Customizing colors
If you like to customize the colors indicating the current config, set the environment variables `CONFIG_REGISTRY_CURRENT_FGCOLOR` and `CONFIG_REGISTRY_CURRENT_BGCOLOR` (refer color codes [here](https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/)):
```
export CONFIG_REGISTRY_CURRENT_FGCOLOR=$(tput setaf 6) # blue text
export CONFIG_REGISTRY_CURRENT_BGCOLOR=$(tput setab 7) # white background
```
Colors in the output can be disabled by setting the
[`NO_COLOR`](http://no-color.org/) environment variable.
-----
# Acknowledgement
The initial version of `config-registry` codebase has been roughly 50% derived from @ahmetb's awesome [kubectx](https://github.com/ahmetb/kubectx). You can see which source files are still kept without major changes today by seeing the license header comments in the source files. A big thanks to @ahmetb and the contributors for all the hard work, and sharing it as an opensource project!