-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add readme and generate cli docs
- Loading branch information
Showing
20 changed files
with
462 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# kubert | ||
|
||
A `kubectx`/`kubens` alternative inspired by [kubie](https://github.com/sbstp/kubie). | ||
`kubert` is a tool that allows you to switch between Kubernetes contexts and namespaces within an isolated shell. | ||
That way, you can have multiple shells open, each with a different context and namespace. | ||
|
||
kubert also has a wrapper for `kubectl` (`kubert kubectl`) to enable you to protect contexts to prevent accidentally running | ||
certain kubectl commands in the wrong context. Checkout the [Protecting contexts](#protecting-contexts) section for more information. | ||
|
||
## Installation | ||
|
||
### Homebrew | ||
|
||
```sh | ||
brew install idebeijer/tap/kubert | ||
``` | ||
|
||
## Usage | ||
|
||
### Switching contexts | ||
|
||
To switch to a different context, run: | ||
```sh | ||
kubert ctx <context-name> | ||
``` | ||
|
||
You can also print out a list of available contexts by running, or if `fzf` is installed, you can select a context from a list: | ||
```sh | ||
kubert ctx | ||
``` | ||
|
||
### Switching namespaces | ||
|
||
To switch to a different namespace, run: | ||
```sh | ||
kubert ns <namespace-name> | ||
``` | ||
|
||
You can also print out a list of available namespaces by running, or if `fzf` is installed, you can select a namespace from a list: | ||
```sh | ||
kubert ns | ||
``` | ||
|
||
### Protecting contexts | ||
|
||
Kubert can be configured to protect certain contexts, to prevent you from accidentally running certain kubectl commands in the wrong context. | ||
This will only work when using kubectl through the `kubert kubectl` command, it will **not** work when using `kubectl` directly. | ||
|
||
To protect a context, you can either set a regex pattern in the Kubert config file, or you can explicitly protect a context. | ||
When a context is protected, you will be prompted to confirm that you want to run a protected kubectl command in that context. | ||
|
||
#### Context protection using a regex pattern | ||
|
||
To protect a context using a regex pattern, you need to set the `protectedByDefaultRegexp` in the Kubert config file. | ||
The following example will protect all contexts that contain `prd` or `prod` in their name: | ||
```yaml | ||
contexts: | ||
protectedByDefaultRegexp: "(prd|prod)" | ||
``` | ||
By default, kubert has set this setting to `null`, which means that no contexts are protected by default. | ||
If you provide an empty string as pattern `""`, all contexts will be protected by default. | ||
|
||
The default regex pattern will be ignored for contexts that have an explicit protection set. | ||
|
||
#### Setting an explicit protect/unprotect | ||
Instead of using a regex pattern, you can also explicitly protect the current context. | ||
When using an explicit protect or unprotect, Kubert will save this in a state file, and the default regex pattern will be ignored for this context. | ||
|
||
To tell Kubert to protect the current context, run: | ||
```sh | ||
kubert context-protection protect | ||
``` | ||
|
||
To tell Kubert to explicitly unprotect the current context, run: | ||
```sh | ||
kubert context-protection unprotect | ||
``` | ||
|
||
The above commands will set an explicit protection for the current context. This means that the context will be (un)protected even if it matches the regex pattern or not. | ||
To delete the explicit protection, run: | ||
```sh | ||
kubert context-protection delete | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## kubert | ||
|
||
kubert is a tool to switch kubernetes contexts and namespaces | ||
|
||
### Synopsis | ||
|
||
kubert is a CLI tool to switch kubernetes contexts and namespaces within an isolated shell so you can have multiple shells with different contexts and namespaces. | ||
|
||
It also includes a wrapper around kubectl to provide the ability to protect contexts by setting a regex pattern to match the context name. This can be used to prevent accidentally running certain kubectl commands in an unwanted context. | ||
Keep in mind, this will only work when using kubectl through the "kubert kubectl" command. Direct commands using just "kubectl" will not be blocked. (If you use this feature, you could set an alias e.g. "k" for "kubert kubectl".) | ||
|
||
|
||
### Options | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
-h, --help help for kubert | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert context-protection](kubert_context-protection.md) - Protect and unprotect contexts | ||
* [kubert ctx](kubert_ctx.md) - Spawn a shell with the selected context | ||
* [kubert kubeconfig](kubert_kubeconfig.md) - Kubeconfig command | ||
* [kubert kubectl](kubert_kubectl.md) - Wrapper for kubectl | ||
* [kubert ns](kubert_ns.md) - Switch to a different namespace | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## kubert context-protection | ||
|
||
Protect and unprotect contexts | ||
|
||
### Synopsis | ||
|
||
Protect and unprotect contexts. | ||
|
||
This will allow you to protect and unprotect contexts for the "kubert kubectl" command. This can be useful if you want to prevent accidentally running certain kubectl commands to a cluster. | ||
Keep in mind, this will only work when using kubectl through the "kubert kubectl" command. Direct commands using just "kubectl" will not be blocked. (If you use this feature, you could set an alias e.g. "k" for "kubert kubectl".) | ||
|
||
Both "protect" and "unprotect" will set an explicit setting for the given context. That means if either of those has been set, kubert will ignore the default setting. If you want to use the default setting again, use "kubert context-protection delete <context>". | ||
|
||
What kubectl commands should be blocked can be configured in the kubert configuration file. | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for context-protection | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert](kubert.md) - kubert is a tool to switch kubernetes contexts and namespaces | ||
* [kubert context-protection delete](kubert_context-protection_delete.md) - Delete protection setting for the current context | ||
* [kubert context-protection info](kubert_context-protection_info.md) - Show protection status for the current context | ||
* [kubert context-protection protect](kubert_context-protection_protect.md) - Protect current context | ||
* [kubert context-protection unprotect](kubert_context-protection_unprotect.md) - Unprotect current context | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## kubert context-protection delete | ||
|
||
Delete protection setting for the current context | ||
|
||
### Synopsis | ||
|
||
Delete protection setting for the current context. | ||
|
||
This will delete the explicit protect/unprotect setting for the current context. So if either "protect" or "unprotect" was set, it will be removed and the default will be used. | ||
|
||
``` | ||
kubert context-protection delete [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for delete | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert context-protection](kubert_context-protection.md) - Protect and unprotect contexts | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## kubert context-protection info | ||
|
||
Show protection status for the current context | ||
|
||
### Synopsis | ||
|
||
Show protection status for the current context. | ||
|
||
This will show if the current context is protected or not. If it is protected, it will show the explicit setting, otherwise it will show the default. | ||
|
||
``` | ||
kubert context-protection info [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for info | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert context-protection](kubert_context-protection.md) - Protect and unprotect contexts | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## kubert context-protection protect | ||
|
||
Protect current context | ||
|
||
### Synopsis | ||
|
||
Protect current context. | ||
|
||
This will set an explicit "protect" for the current context. That means it wil override the default setting. If the current context should use the default again, use "kubert context-protection delete". | ||
|
||
``` | ||
kubert context-protection protect [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for protect | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert context-protection](kubert_context-protection.md) - Protect and unprotect contexts | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## kubert context-protection unprotect | ||
|
||
Unprotect current context | ||
|
||
### Synopsis | ||
|
||
Unprotect current context. | ||
|
||
This will set an explicit "unprotect" for the current context. That means it wil override the default setting. If the current context should use the default again, use "kubert context-protection delete". | ||
|
||
``` | ||
kubert context-protection unprotect [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for unprotect | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert context-protection](kubert_context-protection.md) - Protect and unprotect contexts | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## kubert ctx | ||
|
||
Spawn a shell with the selected context | ||
|
||
### Synopsis | ||
|
||
Start a shell with the KUBECONFIG environment variable set to the selected context. | ||
Kubert will issue a temporary kubeconfig file with the selected context, so that multiple shells can be spawned with different contexts. | ||
|
||
``` | ||
kubert ctx [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for ctx | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert](kubert.md) - kubert is a tool to switch kubernetes contexts and namespaces | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
## kubert kubeconfig | ||
|
||
Kubeconfig command | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for kubeconfig | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--config string config file (default is $HOME/.kubert/config.yaml) | ||
--debug debug mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [kubert](kubert.md) - kubert is a tool to switch kubernetes contexts and namespaces | ||
* [kubert kubeconfig list](kubert_kubeconfig_list.md) - | ||
|
||
###### Auto generated by spf13/cobra on 24-Aug-2024 |
Oops, something went wrong.