Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
f6bce23
Added kgnw watch kubectl get nodes
patmessina May 17, 2019
a1bc188
Adding keit alias.
patmessina Jun 10, 2019
943cafd
Starting restructure, to be more compatible with bash and zsh
patmessina Jun 10, 2019
97d323d
kpfind will now grep over current namespace by default. Add -a flag t…
patmessina Jun 13, 2019
6f555df
Updated kpfind.awk to format things appropriatly after changing kpfind.
patmessina Jun 13, 2019
6ebab6f
kstatus now searches the current namespace, and -a flag will search a…
patmessina Jun 13, 2019
91264be
better error checking
patmessina Jun 13, 2019
863d5fc
Added LICENSE
patmessina Jun 13, 2019
42d9e7c
Corrected formatting
patmessina Jun 13, 2019
8fb943b
Added ImagePullBackOff
patmessina Jun 13, 2019
475114b
conflict with kds, should not delete service as kds is base for describe
patmessina Jun 14, 2019
ec36dcd
Added k-f functions to handle multiple inputs.
patmessina Jun 25, 2019
e0c00a7
Added evicted
eogpat Oct 2, 2019
46fb5ce
Improved kfind.
eogpat Oct 3, 2019
ae99280
Find nodeports
eogpat Oct 3, 2019
e827a13
formatting
eogpat Oct 3, 2019
85ec510
Better error checking and better messages
eogpat Oct 3, 2019
936b85f
Added evicted
patmessina Oct 2, 2019
43d6fa9
Improved kfind.
patmessina Oct 3, 2019
c2e985c
Find nodeports
patmessina Oct 3, 2019
ff3c085
formatting
patmessina Oct 3, 2019
e86d3e3
Better error checking and better messages
patmessina Oct 3, 2019
ee26a51
Removed ./
patmessina Oct 3, 2019
f40e244
Fixed merge conflict
patmessina Nov 5, 2019
7fad7cc
Starting code generation
patmessina Nov 5, 2019
04d93c2
Removed mkkfunc
patmessina Dec 16, 2019
8020ec2
Merging develop
patmessina Dec 16, 2019
2ab4576
add kdfind
patmessina Dec 16, 2019
c1a8558
corrected argument
patmessina Dec 16, 2019
30eab99
Can now generate alaises
patmessina Dec 18, 2019
a24fd4c
Added makefile
patmessina Dec 18, 2019
009c207
moved files
patmessina Dec 18, 2019
f041941
kube-aliases now uses generated aliases
patmessina Dec 18, 2019
fc5a5ca
Removed old aliases
patmessina Dec 18, 2019
1a9ccb5
Started changes to update to generating aliases
patmessina Dec 18, 2019
d47596c
Changed help to display aliases and functions.
patmessina Dec 19, 2019
267176a
Statically compiled
patmessina Dec 19, 2019
16c90b9
Updated readme.
patmessina Dec 19, 2019
f0ae103
refactor to be more useable
eogpat Aug 19, 2021
d332eb2
changed d to del to be consistend
eogpat Aug 19, 2021
7950de4
changed d to del to be consistent
eogpat Aug 19, 2021
c7e332e
renamed
eogpat Aug 19, 2021
6de3323
removed kdrain as it can be generated
eogpat Aug 19, 2021
5e37923
added makefile
eogpat Aug 19, 2021
5100727
generated create aliases binary and removed old
eogpat Aug 19, 2021
513b921
updated customizing aliases
eogpat Aug 19, 2021
e83aa4a
no longer need a small wrapper on file functions as kubectl now works…
eogpat Aug 20, 2021
8c523a7
added create functions
eogpat Aug 20, 2021
d1c9984
also not needed anymore
eogpat Aug 20, 2021
ac07f1a
add some aliases that were removed
eogpat Aug 20, 2021
21fabaa
all the kga commands solve this
eogpat Aug 20, 2021
acdcbcf
didnt need to be its on file, just needed to be an alias
eogpat Aug 20, 2021
14e3c59
Just need to grep status
eogpat Aug 20, 2021
15c0d48
any custom tools should have help, dont need a function for that
eogpat Aug 20, 2021
6fa3df8
removed uneeded file
eogpat Aug 20, 2021
baca7f5
why awk when grep do trick?
eogpat Aug 20, 2021
47c4211
Catch duplication in generated aliases
Dbz Aug 23, 2021
7ce3516
CronJobs should be cj
Dbz Aug 23, 2021
7ea5dd6
Cleanup and regenerate aliases
Dbz Aug 23, 2021
36204c0
removed delete all pods
eogpat Aug 23, 2021
d2ee10e
can no have prefix and suffix commands. Plus cleaned up alias generat…
eogpat Aug 23, 2021
1921bfc
working on tests
eogpat Aug 23, 2021
3d93b45
additonal commands should be able to have prefix and suffix now
eogpat Aug 24, 2021
234f287
uses string builder
eogpat Aug 24, 2021
0819b3f
regenerated aliases
eogpat Aug 24, 2021
d716406
removed broken command.
eogpat Aug 24, 2021
dc7ba84
added additonal commands
eogpat Aug 24, 2021
5a2b59e
Update generate_aliases/pkg/generate/generate.go
patmessina Aug 24, 2021
d8d0508
Update generate_aliases/pkg/generate/generate.go
patmessina Aug 24, 2021
e9191c3
ignore the bin
eogpat Aug 24, 2021
633fc27
dont need to include those file. kubectl creates them with kcd etc.
eogpat Aug 24, 2021
400463a
dont through stack trace on user error
eogpat Aug 24, 2021
7d136e8
Refactor Generate
Dbz Aug 25, 2021
725be97
Merge pull request #26 from Dbz/refactor_generate
patmessina Aug 25, 2021
a1a286d
yay, tests work again and no more map in cmds (#27)
patmessina Aug 26, 2021
962299c
add wasnt behaving correctly. Moved everything down to additional, an…
patmessina Aug 28, 2021
aa6dd1a
Final touches (#30)
patmessina Sep 3, 2021
118235b
Add comments (#31)
Dbz Sep 11, 2021
0ab2e6d
Added aliases for kubectl config
Jan 29, 2022
0736652
Merge pull request #34 from anupamsr/generate-aliases
patmessina Jul 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generate/bin
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Danny Burt

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
261 changes: 192 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,237 @@
# kube-aliases

This is an oh-my-zsh plugin (or source `kube-aliases.plugin.zsh` for bash) to
make working with kubernetes easier. It provides a bunch of bash aliases and
zsh functions. Docs can be found
[here](https://github.com/Dbz/kube-aliases/blob/master/docs/usage), which
clarifies all aliases.
kube-aliases comes with a comprehensive set of aliases for Kubernetes. If
desired, there is a utility tool to generate custom aliases or to change the
aliases automatically. For example, if you prefer `rm` to `del` for deleting.

- [kube-aliases](#kube-aliases)
- [Usage](#usage)
* [General Alias Rules](#general-alias-rules)
* [Generating Aliases](#generating-aliases)
+ [Customizing Aliases Yaml](#customizing-aliases-yaml)
- [resources](#resources)
- [cmds](#cmds)
- [additional](#additional)
- [Installation](#installation)
* [Bash Example](#bash-example)
* [Zsh Example](#zsh-example)
* [Generate Aliases](#generate-aliases)
* [AUR](#aur)


# Usage

## General Alias Rules

Aliases follow the following conventions:

## Usage
```bash
k # kubectl
kc<r> # kubectl create <resource>, e.g. kcd for kubectl create deployment
kdel<r> # kubectl delete <resource>, e.g. kdelp for kubectl delete pods
kd<r> # kubectl describe <resource>, e.g. kdp for kubectl describe pod
kg<r> # kubectl get <resource>, e.g. kgp for kubectl get pods
kg<r>g # kubectl get <resource> -o wide | grep, e.g. kgpg for kubectl get pods -o wide | grep
kga<r> # kubectl get --all-namespaces -o wide <resource>, e.g. kgap for kubectl --all-namespaces -o wide get pods
kga<r>g # kubectl get --all-namespaces -o wide <resource> | grep, e.g. kgap for kubectl --all-namespaces -o wide get pods | grep
kgy<r> # kubectl get <resource> -o yaml, e.g. kgyp for kubectl get pods -o yaml
ke<r> # kubectl edit <resource>, e.g. kep for kubectl edit pods
wkg<resource> # watch kubectl get <resource>, e.g. wkgp for watch kubectl get pods
wkga<r> # watch kubectl get --all-namespaces -o wide <resource>, e.g. wkgap for watch kubectl --all-namespaces -o wide get pods

# Get all names of a resource
kg<r>n # kubectl get <resource> -o go-template --template '{{range .items}}{{.metadata.name}}{{\" \"}}{{end}}'", e.g. kgpn for kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{\" \"}}{{end}}'"
```

## Generating Aliases

Want to generate custom aliases? [Install](#generate-aliases) the latest `generate-kube-aliases`
from releases. Then grab a copy of the default `aliases.yaml` with

```bash
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases.yaml -o ${HOME}/aliases.yaml
```

Modify `aliases.yaml` to make any desired changes and generate the aliases with
```bash
generate-kube-aliases aliases.yaml ~/.kube-aliases
```

There are a few main features of this plugin. First, there are lots of aliases
to make working with Kubernetes easier. Second, there are bash functions to
help with varies tasks such as switching contexts to use different clusters.
and then source it in the `.bashrc` or `.zshrc` file.

### Aliases
```bash
echo "source ${HOME}/.kube-aliases" >> .bashrc
```

Or following the same steps, one can create a smaller list of only additional
content. For example in an `additonal.yaml` file

```yaml
resources:
customresourcefoo:
short: crf

cmds:
- short: g
cmd: get
```

To see a full list of aliases, use
and

```bash
khelp usage
generate-kube-aliases additional.yaml ~/.kube-aliases-additional
echo "source ${HOME}/.additional.yaml" >> .bashrc
```

In general and when it makes sense, aliases follow the following conventions.
would generate the `.kube-aliases-additional` file with content

```bash
k # kubectl
kd<r> # kubectl delete <resource>, e.g. kgp for kubectl delete pods
kds<r> # kubectl describe <resource>, e.g. kdsp for kubectl describe pod
ke<r> # kubectl edit <resource>, e.g. kgp for kubectl edit pods
kg<r> # kubectl get <resource>, e.g. kgp for kubectl get pods
kga<r> # kubectl get --all-namespaces -o wide <resource>, e.g. kgap for kubectl --all-namespaces -o wide get pods
kl # kubectl logs <podname>
klf # kubectl logs -f <podname>: i.e. watch logs live
alias kgcrf="kubectl get customresourcefoo"
```

### Customizing Aliases Yaml

An example small `alias.yaml` file

```yaml
# Kubernetes Resources
resources:
pods:
short: p

# Commands to add to all resources
cmds:
- short: g
cmd: get

# Any other aliases to be generated
additional:
- short: wkgp
cmd: "watch kubectl get pods"
comment: "Extra pod commands."
```

There is also some other useful commands such as the following:
Which will generate the following file

```bash
kcon # create configuration files
kdap # delete all pods within a namespace
kdrain # drain a node
kexec # execute a command in a specified pod,
# default drops user into a shell
kfind # use a regular expression to find items across everything except
# custom resources
kgpns # Get just pod names in a namespace
kpfind # Search through pods with regular expressions
krd # restart a deployment
kstatus # search across namespaces to find pods statuses
# Manage pods.
alias kgp="kubectl get pods"

# Extra pod commands.
alias wkgp="watch kubectl get pods"
```



#### resources

Resources defines Kubernetes resources and what the short letter representation
should be.

```yaml
resources:
<resource>:
short: <short name>
```

For example

```yaml
resources:
pods:
short: p
```

For a more detailed list of aliases, view the [docs](https://github.com/Dbz/kube-aliases/blob/master/docs/usage).
Which will generate aliases `alias k<cmd>p=kubectl <cmd> pod`.

Not everything is currently implemented, but more and more is being added to
the list. If something is missing that is desired, feel free to submit a pull
request.
#### cmds

The cmd block will generate commands on all resources.

## Installation
```yaml
cmd:
- short: <short name>
cmd: <cmd>
# Optional
prefix:
short: <short name>
cmd: <cmd>
# Optional
suffix:
short: <short name>
cmd: <cmd>
```

### Oh-My-Zsh
For example:

```yaml
cmd:
- short: g
cmd: get
```
git clone [email protected]:Dbz/kube-aliases.git ~/.oh-my-zsh/custom/plugins/kube-aliases
echo "plugins+=(kube-aliases)" >> ~/.zshrc

Will generate aliases for get commands for each specified resource in the
format `alias kg<resource>=kubectl get <resource>`. An example with the `pod`
resource is `alias kgp=kubectl get pod`. Prefix and suffix will generate
commands before and after the alias respectively.

Here is an example cmd prefix that will generate `alias wkg<resource short>=watch kubectl get <resource>`:

```yaml
- short: g
cmd: get
prefix:
short: w
cmd: watch
```

You can also manually place `zsh-kuberenetes` inside of `plugins=(...)`

If you have set the `ZSH_CUSTOM` environment variable in your zshrc, then you should modify the git clone directory to be `$ZSH_CUSTOM/plugins/kube-aliases`.
#### additional

### Antigen
Any other aliases can be generated by the following

Add `antigen bundle dbz/kube-aliases` to your antigen bundles in your `.zshrc`
```yaml
additional:
- short: <short>
cmd: <cmd>
comment: <comment>
```

### Zgen
The following is an example we using to generate `alias krd="kubectl rollout restart deployment"`

Add `zgen load dbz/kube-aliases` to your zgen plugins in your `.zshrc`
```yaml
additional:
- short: krd
cmd: "kubectl rollout restart deployment"
comment: "Modifying deployments."
```

### Bash
All commands with the same comment will be grouped together in the generated file under the same comment.

Source `kube-aliases.plugin.zsh` in your `.bashrc`.
# Installation

### Aliases for Kubernetes Extensions
To grab a bunch of aliases without customization get the
`aliases` file and source it in your `bashrc` or `zshrc` file.

#### kubectx
For easy context and namespace switching there is
[kubectx](https://github.com/ahmetb/kubectx). `kubectx` allows users context
switching, and the linked github comes with `kubens` which allows for simple
namespace switching. You can use the following aliases:
## Bash Example

```bash
alias kctx='kubectx'
alias kns='kubens'
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases -o ${HOME}/.kube-aliases
echo "source ${HOME}/.kube-aliases" >> .bashrc
```
#### Kubernetes Metrics Server

To get some metrics from nodes or pods, you can use [Kubernetes Metrics
Server](https://github.com/kubernetes-incubator/metrics-server). There are
the aliases
## Zsh Example

```bash
alias kt='kubectl top'
alias ktn='kubectl top nodes'
alias ktp='kubectl top pods'
curl https://raw.githubusercontent.com/Dbz/kube-aliases/master/aliases -o ${HOME}/.kube-aliases
echo "source ${HOME}/.kube-aliases" >> .zshrc
```

### Trouble Shooting
## Generate Aliases

Coming soon

## AUR

#### Autocomplete
Coming soon

If there is problems with autocomplete, it may be that kubectl is not on the
path when the plugin is loaded. To fix, load plugins after adding kubectl to
path.
Loading