mirror of
https://github.com/ahmetb/kubectx.git
synced 2026-03-06 22:12:16 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e82879a185 | ||
|
|
8c17834c36 | ||
|
|
9ed6690978 | ||
|
|
ed2afa7572 | ||
|
|
5d79a0663d | ||
|
|
e7131add7a | ||
|
|
fd91e53d1f | ||
|
|
b06fcaf054 |
@@ -1,8 +1,8 @@
|
||||
class Kubectx < Formula
|
||||
desc "Tool that can switch between kubectl contexts easily and create aliases"
|
||||
homepage "https://github.com/ahmetb/kubectx"
|
||||
url "https://github.com/ahmetb/kubectx/archive/v0.3.0.tar.gz"
|
||||
sha256 "720b6d9a960a7583983ac84c90d2ff89f4494584cf82a3abb5d4e66e72444621"
|
||||
url "https://github.com/ahmetb/kubectx/archive/v0.3.1.tar.gz"
|
||||
sha256 "4e995f5bec6f41c8d5b6e77f413a58ead077816348e72de26dde3655ec2b7d0b"
|
||||
head "https://github.com/ahmetb/kubectx.git", :branch => "short-names"
|
||||
bottle :unneeded
|
||||
|
||||
|
||||
42
README.md
42
README.md
@@ -1,6 +1,11 @@
|
||||
This repository provides both `kubectx` and `kubens` tools. Purpose of this
|
||||
project is to provide an utility and facilitate discussion about how `kubectl`
|
||||
can manage contexts better.
|
||||
This repository provides both `kubectx` and `kubens` tools.
|
||||
|
||||
|
||||
**`kubectx`** help you switch between clusters back and forth:
|
||||

|
||||
|
||||
**`kubens`** help you switch between Kubernetes namespaces smoothly:
|
||||

|
||||
|
||||
# kubectx(1)
|
||||
|
||||
@@ -9,15 +14,12 @@ kubectx is an utility to manage and switch between kubectl(1) contexts.
|
||||
```
|
||||
USAGE:
|
||||
kubectx : list the contexts
|
||||
kubectx <NAME> : switch to context
|
||||
kubectx <NAME> : switch to context <NAME>
|
||||
kubectx - : switch to the previous context
|
||||
kubectx <NEW_NAME>=<NAME> : create alias for context
|
||||
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
||||
kubectx -h,--help : show this message
|
||||
```
|
||||
|
||||
Purpose of this project is to provide an utility and facilitate discussion
|
||||
about how `kubectl` can manage contexts better.
|
||||
|
||||
### Usage
|
||||
|
||||
```sh
|
||||
@@ -73,20 +75,34 @@ Active namespace is "default".
|
||||
|
||||
**For macOS:**
|
||||
|
||||
> Use [Homebrew](https://brew.sh/) package manager:
|
||||
:tada: kubectx is now in Homebrew! :confetti_ball:
|
||||
|
||||
> Use the [Homebrew](https://brew.sh/) package manager:
|
||||
>
|
||||
> brew install kubectx
|
||||
>
|
||||
> brew tap ahmetb/kubectx https://github.com/ahmetb/kubectx.git
|
||||
> brew install kubectx
|
||||
> this will also set up bash/zsh completion scripts automatically.
|
||||
|
||||
Running `brew install` with `--with-short-names` will install tools with names
|
||||
`kctx` and `kns` to prevent prefix collision with `kubectl` name.
|
||||
|
||||
> Note: If you installed kubectx before it was accepted to Homebrew core
|
||||
> repository, reinstall with:
|
||||
> `brew untap ahmetb/kubectx && brew uninstall --force kubectx && brew update && brew install kubectx`
|
||||
|
||||
**Other platforms:**
|
||||
|
||||
> Download the `kubectx` script, make it executable and add it to your PATH. You
|
||||
> can also install bash/zsh [completion scripts](completion/) manually.
|
||||
- Download the `kubectx` script
|
||||
- Add it somewhere in your PATH
|
||||
- Make it executable (`chmod +x`)
|
||||
- You can also install bash/zsh [completion scripts](completion/) manually.
|
||||
|
||||
-----
|
||||
|
||||
Disclaimer: This is not an official Google product.
|
||||
|
||||
|
||||
#### Stargazers over time
|
||||
|
||||
[](https://starcharts.herokuapp.com/ahmetb/kubectx)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ PREV=""
|
||||
if [ -f "$KUBECTX" ]; then
|
||||
# show '-' only if there's a saved previous context
|
||||
local PREV=$(cat "${KUBECTX}")
|
||||
_arguments "1: :((-\:Back\ to\ ${PREV} \
|
||||
_arguments "1: :((- \
|
||||
$(kubectl config get-contexts --output='name')))"
|
||||
else
|
||||
_arguments "1: :($(kubectl config get-contexts --output='name'))"
|
||||
|
||||
BIN
img/kubectx-demo.gif
Normal file
BIN
img/kubectx-demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 163 KiB |
BIN
img/kubens-demo.gif
Normal file
BIN
img/kubens-demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 226 KiB |
14
kubectx
14
kubectx
@@ -36,9 +36,9 @@ usage() {
|
||||
cat <<"EOF"
|
||||
USAGE:
|
||||
kubectx : list the contexts
|
||||
kubectx <NAME> : switch to context
|
||||
kubectx <NAME> : switch to context <NAME>
|
||||
kubectx - : switch to the previous context
|
||||
kubectx <NEW_NAME>=<NAME> : create alias for context
|
||||
kubectx <NEW_NAME>=<NAME> : rename context <NAME> to <NEW_NAME>
|
||||
kubectx -h,--help : show this message
|
||||
EOF
|
||||
exit 1
|
||||
@@ -107,7 +107,7 @@ cluster_of_context() {
|
||||
-o=jsonpath="{.contexts[?(@.name==\"${1}\")].context.cluster}"
|
||||
}
|
||||
|
||||
alias_context() {
|
||||
rename_context() {
|
||||
local old_name="${1}"
|
||||
local new_name="${2}"
|
||||
|
||||
@@ -119,11 +119,7 @@ alias_context() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
kubectl config set-context "${new_name}" \
|
||||
--cluster="${old_cluster}" \
|
||||
--user="${old_user}" \
|
||||
|
||||
echo "Aliased \"${old_name}\" as \"${new_name}\"." >&2
|
||||
kubectl config rename-context "${old_name}" "${new_name}"
|
||||
}
|
||||
|
||||
main() {
|
||||
@@ -141,7 +137,7 @@ main() {
|
||||
echo "error: unrecognized flag \"${1}\"" >&2
|
||||
usage
|
||||
elif [[ "${1}" =~ (.+)=(.+) ]]; then
|
||||
alias_context "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]}"
|
||||
rename_context "${BASH_REMATCH[2]}" "${BASH_REMATCH[1]}"
|
||||
else
|
||||
set_context "${1}"
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user