-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bash_profile
54 lines (53 loc) · 1.98 KB
/
.bash_profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# kubectl
source <(kubectl completion bash)
alias k=kubectl
complete -F __start_kubectl k
alias ka="kubectl apply -f"
alias kg="kubectl get -o wide"
alias ktp="kubectl top pods"
alias ktn="kubectl top nodes"
alias kgp="kubectl get pods -o wide"
alias kgpv="kubectl get pv -o wide"
alias kgpvc="kubectl get pvc -o wide"
alias kgcm="kubectl get cm -o wide"
alias kgn="kubectl get nodes -o wide"
alias kgns="kubectl get ns -o wide --show-labels"
alias kgs="kubectl get svc -o wide"
alias kgvs="kubectl get vs -o wide"
alias kgrs="kubectl get rs -o wide"
alias kgap="kubectl get authorizationpolicies.security.istio.io -o wide"
alias kgpo="kubectl get policy -o wide"
alias kgpfail="kubectl get pods -o wide -A | grep -v 'Running' | grep -v 'Completed'"
alias kl="kubectl logs"
alias kcall='kubectl get nodes --no-headers | awk '\''{print $1}'\'' | xargs -I {} sh -c '\''echo {} ; kubectl describe node {} | grep Allocated -A 5 | grep -ve Event -ve Allocated -ve percent -ve -- ; echo '\'''
# kubectl wrapper to prevent accidental deletion
kubectl() {
kube_prod_context_regex="-prod-" #Change to a Regex that matches the prod cluster's context
kube_prompt=false
if [[ " $@ " =~ " delete " ]] ; then
kube_context=$(kubectl config current-context)
if [[ "$*" == *"--context"* ]]; then
if [[ "$*" =~ .*"$kube_prod_context_regex".* ]]; then kube_prompt=true; fi
elif [[ "$kube_context" =~ .*"$kube_prod_context_regex".* ]]; then kube_prompt=true; fi
fi
if [ "$kube_prompt" = true ]; then
read -p "kubectl delete in production (y or n)?" yn
case $yn in
[Yy]* ) command kubectl "$@";;
* ) echo abort... ;;
esac
else
command kubectl "$@"
fi
}
# Find all resources in a namespace
kgall() {
if [ $# -eq 0 ]
then
echo "Define namespace to search."
else
echo "Searching all resources in namespace $1"
kubectl get namespace $1 &&
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n $1
fi
}