-
Notifications
You must be signed in to change notification settings - Fork 1
/
registry-port-forward.sh
executable file
·68 lines (56 loc) · 1.18 KB
/
registry-port-forward.sh
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
#!/usr/bin/env bash
set -ue -o pipefail
service="k8s-registry-port-forward"
run_systemd() {
description="Port Forward for Container Registry of k8s dev environment"
cleanup_systemd
systemd-run --user \
--unit="$service.service" \
--description="$description" \
--same-dir \
--setenv="KUBECONFIG=$KUBECONFIG" \
--collect \
kubectl port-forward -n kube-system svc/docker-registry 30666:5000
}
cleanup_systemd() {
systemctl --user stop "$service.service" 2> /dev/null || true
}
run_launchd() {
cleanup_launchd
launchctl submit \
-l "$service" \
-p "$(command -v kubectl)" \
-- kubectl --kubeconfig="$KUBECONFIG" port-forward -n kube-system svc/docker-registry 30666:5000
}
cleanup_launchd() {
launchctl remove "$service" 2> /dev/null || true
}
if command -v systemctl > /dev/null; then
run="run_systemd"
cleanup="cleanup_systemd"
elif command -v launchctl > /dev/null; then
run="run_launchd"
cleanup="cleanup_launchd"
else
echo "No supported init system found"
exit 1
fi
help() {
cat << EOF >&2
Usage:
$0 up
$0 down
EOF
exit 1
}
case "${1:-}" in
"up")
$run
;;
"down")
$cleanup
;;
*)
help
;;
esac