Created
March 3, 2019 16:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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