-
Notifications
You must be signed in to change notification settings - Fork 2
/
kubernetes.sh
executable file
·163 lines (133 loc) · 3.17 KB
/
kubernetes.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# config
MASTER="127.0.0.1"
NODEIP="172.31.255.1"
SERVICERANGE="172.18.0.0/24"
NAME="k8s.$1"
IMAGE="gcr.io/google_containers/hyperkube-amd64:v1.9.2"
ETCD_SERVERS="http://127.0.0.1:4001"
RESTART="no"
## functions
remove_container () {
if docker ps -a | grep "$NAME" > /dev/null; then
docker stop "$NAME"
docker rm "$NAME" && echo "old $NAME container removed"
fi
}
case "$1" in
"pull-only")
docker pull "$IMAGE"
;;
"get-binary")
[ ! -d bin ] && mkdir bin
docker run --rm -ti \
-v $PWD/bin/:/tmp/bin/:Z \
--entrypoint cp $IMAGE \
-- /hyperkube /tmp/bin/
./bin/hyperkube --version
ln -vs hyperkube ./bin/kubectl
;;
"apiserver")
echo "preparing to run container $NAME"
remove_container "$NAME"
docker run \
--name "$NAME" \
--detach \
--restart $RESTART \
--net host \
$IMAGE /hyperkube apiserver \
--insecure-bind-address=0.0.0.0 \
--external-hostname=$MASTER \
--bind-address=$MASTER \
--secure-port=0 \
--etcd-servers=$ETCD_SERVERS \
--service-cluster-ip-range=$SERVICERANGE \
--v=2
;;
"controller-manager")
echo "preparing to run container $NAME"
remove_container "$NAME"
docker run \
--name "$NAME" \
--detach \
--restart $RESTART \
--net host \
$IMAGE /hyperkube controller-manager \
--master=$MASTER:8080 \
--v=2
;;
"scheduler")
echo "preparing to run container $NAME"
remove_container "$NAME"
docker run \
--name "$NAME" \
--detach \
--restart $RESTART \
--net host \
$IMAGE /hyperkube scheduler \
--master=$MASTER:8080 \
--v=2
;;
"kubelet")
echo "preparing to run container $NAME"
echo "WARNING: kubelet in container is very experimental as will probable fail. Use kubelet-bare to get working enviroment."
remove_container "$NAME"
docker run \
--name "$NAME" \
--detach \
--restart $RESTART \
--net host \
--privileged \
--volume /var/run:/var/run:rw \
--volume /var/lib/docker:/var/lib/docker:rw \
--volume /var/lib/kubelet:/var/lib/kubelet:rw \
--volume /sys:/sys:ro \
$IMAGE /hyperkube kubelet \
--api_servers=http://$MASTER:8080 \
--address=$NODEIP \
--enable-server \
--v=2 \
--node-ip 127.0.0.1
;;
"kubelet-bare")
echo "preparing to run bare $NAME"
if [ ! -x "./bin/hyperkube" ]; then
echo "./bin/hyperkube is missing or not executable"
echo "Please run ./kubernetes.sh get-binary because hyperkube binary is required to run kubelet-bare"
exit 1
fi
NODE_IP="$2"
if [ "$NODE_IP" == "" ]; then
echo "NODE_IP is missing"
exit 1
fi
sed "s/{{ apiserver }}/$MASTER/g" kubeconfig > kubeconfig_edited
./bin/hyperkube kubelet \
--kubeconfig kubeconfig_edited \
--hostname-override $NODE_IP \
--address=0.0.0.0 \
--node-ip $NODE_IP \
--cgroup-driver=systemd \
--enable-server \
--fail-swap-on=false \
--v=2
;;
"proxy")
echo "preparing to run container $NAME"
remove_container "$NAME"
docker run \
--name "$NAME" \
--detach \
--restart $RESTART \
--net host \
--privileged \
$IMAGE /hyperkube proxy \
--bind-address=$NODEIP \
--master=$MASTER:8080 \
--v=2
;;
*)
echo "unknown component $1"
echo "available: apiserver, controller-manager, scheduler, kubelet, proxy, pull-only, get-binary"
;;
esac