Skip to content

Commit

Permalink
Add functions for kubectl commands
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-nath authored Jun 26, 2023
1 parent e332aee commit 0bec4e3
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions dev-setup/.functions
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,58 @@ function find_top_files() {
local file_pattern="${1:-*.java}"
find . -name "$file_pattern" -type f -exec wc -l {} + | sort -rn | head -n 6 | tail +2
}

# kubectl
# get pods by app name
kgpol() { k get pods -l=app="$1"; }

# get deployments by app name
kgdepl() { k get deployments -l=app="$1"; }

# get services by app name
kgsvcl() { k get svc -l=app="$1"; }

# delete pod
krmpo() { k delete pod "$1" --wait=false; }

# grep a string in a cm
kgrepcm() { k describe cm "$1" | grep "$2"; }

# get logs for a pod
kl() { k logs "$1" | less; }

# get logs from previous container run
klp() { k logs -p "$1" | less; }

# follow logs
klf() { k logs "$1" --follow; }

# tail logs
klt() { k logs "$1" --tail "$2"; }

# follow and tail logs
klft() { k logs "$1" --follow --tail "$2"; }

# get pod details in yaml format
kgpoy() { k get pod "$1" -o yaml | less; }

# get deployment details in yaml format
kgdepy() { k get deployment "$1" -o yaml | less; }

# get svc details in yaml format
kgsvcy() { k get service "$1" -o yaml | less; }

# get pod details in json format
kgpoj() { k get pod "$1" -o json | less; }

# get deployment details in json format
kgdepj() { k get deployment "$1" -o json | less; }

# get svc details in json format
kgsvcj() { k get service "$1" -o json | less; }

# scale deployment
kscale() { k scale deployment "$1" --replicas="$2"; }

# enter into pod's bash shell
kbash() { kubectl -it exec "$1" bash; }

0 comments on commit 0bec4e3

Please sign in to comment.