forked from jmhobbs/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash-kubernetes.symlink
87 lines (75 loc) · 2.32 KB
/
bash-kubernetes.symlink
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function __kubectl_cluster {
if [ "$KUBECONFIG" != "" ]; then
CLUSTER=$(basename $KUBECONFIG 2> /dev/null)
if [ "$CLUSTER" == "kubeconfig" ]; then
CLUSTER=$(dirname $KUBECONFIG | sed 's/.*\///')
fi
echo -ne "[$KUBE_NAMESPACE@$CLUSTER]"
else
if [ "$KUBE_NAMESPACE" != "" ]; then
CLUSTER="$(kubectl config current-context)"
echo -ne "[$KUBE_NAMESPACE@$CLUSTER]"
fi
fi
}
function use-cluster {
if [ -f "$HOME/.kube/$1" ]; then
export KUBECONFIG="$HOME/.kube/$1"
elif [ -f "$HOME/Working/kubernetes/cluster/$1/kubeconfig" ]; then
export KUBECONFIG="$HOME/Working/kubernetes/cluster/$1/kubeconfig"
else
export KUBECONFIG=""
kubectl config use-context "$1" > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo "Invalid cluster name"
return 1
fi
fi
if [ "$2" != "" ]; then
export KUBE_NAMESPACE="$2"
else
export KUBE_NAMESPACE="default"
fi
}
function _use_cluster_completions {
COMPREPLY=($(compgen -W "$(kubectl config get-contexts | sed 's/^\** *//' | awk '{print $1}' | sed '1d')" "${COMP_WORDS[1]}"))
}
complete -F _use_cluster_completions use-cluster
function use-namespace {
if [ "$1" != "" ]; then
export KUBE_NAMESPACE="$1"
else
export KUBE_NAMESPACE="default"
fi
}
export KUBE_NAMESPACE="default"
alias kc='kubectl --namespace="$KUBE_NAMESPACE"'
function kcdb {
kc get pod debug > /dev/null
if [ $? == "0" ]; then
kc exec debug --tty -i -- env COLUMNS=$COLUMNS LINES=$LINES bash
else
kc run debug --labels="debug=true,instance=$KUBE_NAMESPACE" --generator=run-pod/v1 --image=jmhobbs/debug-box:v3 --tty -i -- env COLUMNS=$COLUMNS LINES=$LINES bash
fi
}
function kccalicoctl {
kc get pod calicoctl > /dev/null
if [ $? == "0" ]; then
kc exec calicoctl --tty -i -- env COLUMNS=$COLUMNS LINES=$LINES
else
kc run calicoctl --labels="debug=true" --generator=run-pod/v1 --image=calico/ctl:v1.3.0 --tty -i -- env COLUMNS=$COLUMNS LINES=$LINES sh
fi
}
function kcsh {
if [ "$2" != "" ]; then
kc exec $1 -c $2 --tty -i -- env COLUMNS=$COLUMNS ROWS=$ROWS TERM=$TERM sh
else
kc exec $1 --tty -i -- env COLUMNS=$COLUMNS ROWS=$ROWS TERM=$TERM sh
fi
}
function node-info {
aws ec2 describe-instances --filters Name=private-dns-name,Values=$1
}
function unpack-site-config {
base64 --decode | gunzip | jq .
}