20 Commits

Author SHA1 Message Date
Ahmet Alp Balkan
80336137bd Merge pull request #32 from shiroyasha/installation-steps-linux
Example installation steps on Linux
2018-03-30 10:26:18 -07:00
Ahmet Alp Balkan
1c9b5c54e8 Merge pull request #33 from jonmosco/utils_bash
Incorporate utils.bash into each executable to help simplify packaging for Linux and other platforms.  This adds to PR #32
2018-03-15 10:17:48 -07:00
Jon Mosco
b188f4da88 Incorporate utils.bash into each executable to help simplify packaging
for Linux and other platforms.  This adds to PR #32

remove unused functions
2018-03-15 12:34:18 -04:00
Igor Šarčević
57893cb668 Example installation steps on Linux 2018-03-10 13:17:09 +01:00
Ahmet Alp Balkan
8da629d98e Update README.md 2018-03-01 10:27:55 -08:00
Ahmet Alp Balkan
b2992aa0df Update readme to add fish completion support 2018-01-18 10:18:50 -08:00
Ahmet Alp Balkan
2f33693466 Merge pull request #26 from ichekrygin/master
Add Fish Shell Completions
2018-01-18 10:18:04 -08:00
Illya Chekrygin
c813642dc3 Add fish completions for kubectx and kubens 2018-01-17 23:23:53 -08:00
Ahmet Alp Balkan
12575f8ce4 Update README.md 2018-01-12 15:30:38 -08:00
Ahmet Alp Balkan
46d4236f1a Update README.md 2018-01-12 15:29:57 -08:00
Ahmet Alp Balkan
7ae68ada83 Update README.md 2018-01-02 14:58:33 -08:00
Ahmet Alp Balkan
146b67d2b0 Merge pull request #20 from knil-sama/knil-sama-readme-typo
Update README.md
2017-12-20 09:04:05 -08:00
Clement Demonchy
e3ceb14db5 Update README.md
Correct typo soemwhere -> somewhere
2017-12-20 14:16:28 +01:00
Ahmet Alp Balkan
6e250aecb6 Remove Formula/*, it's now in homebrew-core
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
2017-12-14 15:21:10 -08:00
Ahmet Alp Balkan
d613c37c16 Update README.md 2017-12-12 10:34:58 -08:00
Ahmet Alp Balkan
61f1aa8fd7 Update README.md 2017-12-12 10:34:44 -08:00
Ahmet Alp Balkan
8390860474 Update README.md 2017-11-17 10:15:31 -08:00
Ahmet Alp Balkan
394288edc0 Update README.md 2017-11-15 12:49:33 -08:00
Ahmet Alp Balkan
dc6d2e57b3 README.md: Add user testimonials 2017-11-15 12:48:05 -08:00
Ahmet Alp Balkan
aa215b9eeb Update installation instructions for non-macOS 2017-11-15 12:41:03 -08:00
7 changed files with 68 additions and 73 deletions

View File

@@ -1,26 +0,0 @@
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.1.tar.gz"
sha256 "4e995f5bec6f41c8d5b6e77f413a58ead077816348e72de26dde3655ec2b7d0b"
head "https://github.com/ahmetb/kubectx.git", :branch => "short-names"
bottle :unneeded
option "with-short-names", "link as \"kctx\" and \"kns\" instead"
def install
bin.install "kubectx" => build.with?("short-names") ? "kctx" : "kubectx"
bin.install "kubens" => build.with?("short-names") ? "kns" : "kubens"
include.install "utils.bash"
bash_completion.install "completion/kubectx.bash" => "kubectx"
bash_completion.install "completion/kubens.bash" => "kubens"
zsh_completion.install "completion/kubectx.zsh" => "_kubectx"
zsh_completion.install "completion/kubens.zsh" => "_kubens"
end
test do
system "which", build.with?("short-names") ? "kctx" : "kubectx"
system "which", build.with?("short-names") ? "kns" : "kubens"
end
end

View File

@@ -37,7 +37,7 @@ Context "dublin" set.
Aliased "gke_ahmetb_europe-west1-b_dublin" as "dublin".
```
`kubectx` supports <kbd>Tab</kbd> completion on bash/zsh shells to help with
`kubectx` supports <kbd>Tab</kbd> completion on bash/zsh/fish shells to help with
long context names. You don't have to remember full context names anymore.
-----
@@ -67,35 +67,63 @@ Context "test" set.
Active namespace is "default".
```
`kubens` also supports <kbd>Tab</kbd> completion on bash/zsh shells.
`kubens` also supports <kbd>Tab</kbd> completion on bash/zsh/fish shells.
-----
## Installation
**For macOS:**
**macOS:**
:tada: kubectx is now in Homebrew! :confetti_ball:
:confetti_ball: Use the [Homebrew](https://brew.sh/) package manager:
> Use the [Homebrew](https://brew.sh/) package manager:
>
> brew install kubectx
>
> this will also set up bash/zsh completion scripts automatically.
brew install kubectx
Running `brew install` with `--with-short-names` will install tools with names
This command will set up bash/zsh/fish 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`
- If you like to add context/namespace info to your shell prompt (`$PS1`),
I recommend trying out [kube-ps1](https://github.com/jonmosco/kube-ps1).
**Other platforms:**
**Linux:**
- 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.
Since `kubectx`/`kubens` are written in Bash, you should be able to instal
them to any POSIX environment that has Bash installed.
- Download the `kubectx`, and `kubens` scripts.
- Either:
- save them all to somewhere in your `PATH`,
- or save them to a directory, then create symlinks to `kubectx`/`kubens` from
somewhere in your `PATH`, like `/usr/local/bin`
- Make `kubectx` and `kubens` executable (`chmod +x ...`)
- Figure out how to install bash/zsh/fish [completion scripts](completion/).
Example installation steps:
``` bash
sudo git clone https://github.com/ahmetb/kubectx /opt/kubectx
sudo ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
sudo ln -s /opt/kubectx/kubens /usr/local/bin/kubens
```
-----
#### Users
| What are others saying about kubectx? |
| ---- |
| _“Thank you for kubectx & kubens - I use them all the time & have them in my k8s toolset to maintain happiness :) ”_ [@pbouwer](https://twitter.com/pbouwer/status/925896377929949184) |
| _“I can't imagine working without kubectx and especially kubens anymore. It's pure gold.”_ [@timoreimann](https://twitter.com/timoreimann/status/925801946757419008) |
| _“I'm liking kubectx from @ahmetb, makes it super-easy to switch #Kubernetes contexts [...]”_ &mdash; [@lizrice](https://twitter.com/lizrice/status/928556415517589505) |
| _“Also using it on a daily basis. This and my zsh config that shows me the current k8s context 😉”_ [@puja108](https://twitter.com/puja108/status/928742521139810305) |
| _“Lately I've found myself using the kubens command more than kubectx. Both very useful though :-)”_ [@stuartleeks](https://twitter.com/stuartleeks/status/928562850464907264) |
| _“yeah kubens rocks!”_ [@embano1](https://twitter.com/embano1/status/928698440732815360) |
| _“Special thanks to Ahmet Alp Balkan for creating kubectx, kubens, and kubectl aliases, as these tools made my life better.”_ [@strebeld](https://medium.com/@strebeld/5-ways-to-enhance-kubectl-ux-97c8893227a)
> If you liked `kubectx`, you may like my [`kubectl-aliases`](https://github.com/ahmetb/kubectl-aliases) project, too.
-----

3
completion/kubectx.fish Normal file
View File

@@ -0,0 +1,3 @@
# kubectx
complete -f -c kubectx -a "- (kubectl config get-contexts --output='name')"

3
completion/kubens.fish Normal file
View File

@@ -0,0 +1,3 @@
# kubens
complete -f -c kubens -a "(kubectl get ns -o=custom-columns=NAME:.metadata.name --no-headers)"

17
kubectx
View File

@@ -21,15 +21,6 @@
set -eou pipefail
IFS=$'\n\t'
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"
if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
source "${SCRIPT_DIR}/utils.bash"
else
source "${SCRIPT_DIR}/../include/utils.bash"
fi
KUBECTX="${HOME}/.kube/kubectx"
usage() {
@@ -44,6 +35,14 @@ EOF
exit 1
}
current_context() {
kubectl config view -o=jsonpath='{.current-context}'
}
get_contexts() {
kubectl config get-contexts -o=name | sort -n
}
list_contexts() {
set -u pipefail
local cur="$(current_context)"

17
kubens
View File

@@ -21,15 +21,6 @@
set -eou pipefail
IFS=$'\n\t'
SCRIPT_DIR="$(dirname "$( readlink -f "${0}" 2>/dev/null || \
python -c "import os,sys; print(os.path.realpath(sys.argv[1]))" "${0}" )")"
if [[ -f "${SCRIPT_DIR}/utils.bash" ]]; then
source "${SCRIPT_DIR}/utils.bash"
else
source "${SCRIPT_DIR}/../include/utils.bash"
fi
KUBENS_DIR="${HOME}/.kube/kubens"
usage() {
@@ -53,6 +44,14 @@ current_namespace() {
fi
}
current_context() {
kubectl config view -o=jsonpath='{.current-context}'
}
get_namespaces() {
kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'
}
namespace_file() {
local ctx="${1}"
echo "${KUBENS_DIR}/${ctx}"

View File

@@ -1,11 +0,0 @@
current_context() {
kubectl config view -o=jsonpath='{.current-context}'
}
get_contexts() {
kubectl config get-contexts -o=name | sort -n
}
get_namespaces() {
kubectl get namespaces -o=jsonpath='{range .items[*].metadata.name}{@}{"\n"}{end}'
}