-
Notifications
You must be signed in to change notification settings - Fork 1
/
.kubefuncs
75 lines (66 loc) · 2.16 KB
/
.kubefuncs
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
function kbash() {
kubectl get pod curl > /dev/null 2>&1
if [ $? -ne 0 ]; then
# Not running, create a new one
kubectl run curl --image=pj3677/curlimage -i --tty
else
echo 'Attaching...'
podname=$(kubectl get pods --selector=run=curl -o jsonpath='{.items[*].metadata.name}')
kubectl attach ${podname} -c curl -i -t
fi
}
function kdash() {
kubectl proxy &
open http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
}
function kproxy() {
kubectl proxy &
open http://localhost:8001/api/v1/namespaces/default/services/http:$1:$2/proxy/
}
function podip {
echo "Getting IP for '$1'"
kubectl describe pod $1 | grep IP | awk '{print $2}'
}
# Attach to running pod
function ka() {
kubectl attach $1 -i
}
# Forwards local port to pods container port
function kf() {
if [ -z "$1" ]; then
kubectl get pods -o name
else
containerPort=$(kubectl get po $1 -o jsonpath='{.spec.containers[0].ports[0].containerPort}')
if [ -z "$containerPort" ]; then
echo "No container port"
else
kubectl port-forward $1 8080:$containerPort
fi
fi
}
# Deploys metallb to the current cluster
function metallb() {
# make sure to install `brew install chipmk/tap/docker-mac-net-connect`
helm upgrade --install --namespace metallb-system --create-namespace --repo https://metallb.github.io/metallb metallb metallb
kubectl wait po -n metallb-system --timeout=600s -l app.kubernetes.io/name=metallb -l app.kubernetes.io/component=controller --for condition=Ready
KIND_NET_CIDR=$(docker network inspect kind -f '{{(index .IPAM.Config 0).Subnet}}')
METALLB_IP_START=$(echo ${KIND_NET_CIDR} | sed "[email protected]/[email protected]@")
METALLB_IP_END=$(echo ${KIND_NET_CIDR} | sed "[email protected]/[email protected]@")
METALLB_IP_RANGE="${METALLB_IP_START}-${METALLB_IP_END}"
kubectl apply -f - <<EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: lbpool
namespace: metallb-system
spec:
addresses:
- ${METALLB_IP_RANGE}
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: l2adv
namespace: metallb-system
EOF
}