Skip to content

Instantly share code, notes, and snippets.

@mustafakirimli
Created March 3, 2019 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafakirimli/c5d04a2927302aa3a1aed20196bab74f to your computer and use it in GitHub Desktop.
Save mustafakirimli/c5d04a2927302aa3a1aed20196bab74f to your computer and use it in GitHub Desktop.
Some small shortcuts on Kubernetes for daily tasks. Be careful and test before using on production
function kpod {
# $1 pod name
# $2 namespace
# $3 extra args for command
podName=$1
envName=$2
eArgs=$3
kubectl get pod -n $envName -o yaml $podName $eArgs
}
function kgrep {
# $1 resource name
# $2 namespace
# $3 resource type (pod svc node ..)
# $4 extra args for command
resName="NR==1 || /${1}/"
pEnv="-n $2"
resType="${3:-pod}"
eArgs=$4
[ -z "$2" ] && pEnv="--all-namespaces"
kubectl get $resType $pEnv $eArgs | awk "${resName}"
}
function klogs {
# $1 pod name
# $2 namespace
# $3 extra args for command
podName=$1
envName=$2
eArgs=$3
kubectl logs -f $podName -n $envName --since=0s $eArgs
}
function kdelete {
# $1 resource name
# $2 namespace
# $3 resource type (pod svc node ..)
# $4 extra args for command
podName=$1
envName=$2
resType="${3:-pod}"
eArgs=$3
kubectl delete $resType $podName -n $envName $eArgs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment