-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathrun-kubectl.sh
executable file
·74 lines (58 loc) · 1.37 KB
/
run-kubectl.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
69
70
71
72
73
74
#!/bin/sh
# Run docker container containing kubectl tools and scripts
# @author Fabrice Jammes
set -e
set -x
DIR=$(cd "$(dirname "$0")"; pwd -P)
KUBECONFIG="$DIR"/dot-kube
usage() {
cat << EOD
Usage: $(basename "$0") [options]
Available options:
-C Command to launch inside container
-K Path to k8s configuration file,
default to $DIR if readable
-h This message
Run docker container containing k8s management tools (helm,
kubectl, ...) and scripts.
EOD
}
set -x
# Get the options
while getopts hC:K: c ; do
case $c in
C) CMD="${OPTARG}" ;;
K) KUBECONFIG="${OPTARG}" ;;
h) usage ; exit 0 ;;
\?) usage ; exit 2 ;;
esac
done
shift "$((OPTIND-1))"
if [ $# -ne 0 ] ; then
usage
exit 2
fi
case "$KUBECONFIG" in
/*) ;;
*) echo "expect absolute path" ; exit 2 ;;
esac
# strip trailing slash
KUBECONFIG=$(echo $KUBECONFIG | sed 's%\(.*[^/]\)/*%\1%')
if [ ! -r "$KUBECONFIG" ]; then
echo "ERROR: incorrect KUBECONFIG file: $KUBECONFIG"
exit 2
fi
if [ -z "${CMD}" ]
then
BASH_OPTS="-it --volume "$DIR"/kubectl/scripts:/root/scripts"
CMD="bash"
fi
# Launch container
#
# Use host network to easily publish k8s dashboard
IMAGE=k8sschool/kubectl
docker pull "$IMAGE"
docker run $BASH_OPTS --net=host \
--rm \
--volume "$KUBECONFIG":/root/.kube \
"$IMAGE" $CMD