forked from vyshane/docker-compose-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
kube-up.sh
executable file
·96 lines (81 loc) · 3.43 KB
/
kube-up.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
#!/bin/bash
set -e
this_dir=$(cd -P "$(dirname "$0")" && pwd)
require_command_exists() {
command -v "$1" >/dev/null 2>&1 || { echo "$1 is required but is not installed. Aborting." >&2; exit 1; }
}
require_command_exists kubectl
require_command_exists docker
docker info > /dev/null
if [ $? != 0 ]; then
echo "A running Docker engine is required. Is your Docker host up?"
exit 1
fi
if [[ ! $(docker version --format {{.Server.Version}}) == "1.10.3" ]]; then
echo "Error: You should be running docker 1.10.3"
exit 1
fi
echo "Setting up kubectl context"
api_address="localhost"
if command -v docker-machine >/dev/null 2>&1; then
api_address=$(docker-machine ip)
fi
kubectl config set-cluster local --server="http://$api_address:8080" >/dev/null 2>&1
kubectl config set-context local --cluster=local >/dev/null 2>&1
kubectl config use-context local >/dev/null 2>&1
if kubectl cluster-info &> /dev/null; then
echo "Kubernetes is already running"
exit 1
fi
echo "Cleaning up last kubernetes run (may ask for sudo)"
if command -v docker-machine >/dev/null 2>&1; then
docker-machine ssh $DOCKER_MACHINE_NAME "mount | grep -o 'on /var/lib/kubelet.* type' | cut -c 4- | rev | cut -c 6- | rev | sort -r | xargs --no-run-if-empty sudo umount"
docker-machine ssh $DOCKER_MACHINE_NAME "sudo rm -Rf /var/lib/kubelet"
docker-machine ssh $DOCKER_MACHINE_NAME "sudo mkdir -p /var/lib/kubelet"
docker-machine ssh $DOCKER_MACHINE_NAME "sudo mount --bind /var/lib/kubelet /var/lib/kubelet"
docker-machine ssh $DOCKER_MACHINE_NAME "sudo mount --make-shared /var/lib/kubelet"
docker-machine ssh $DOCKER_MACHINE_NAME "sudo mkdir -p /etc/kubernetes/manifests-multi"
docker-machine scp -r "$this_dir/manifests-multi/" "$DOCKER_MACHINE_NAME:/tmp" 2>&1 > /dev/null
docker-machine ssh $DOCKER_MACHINE_NAME "sudo cp -fr /tmp/manifests-multi/ /etc/kubernetes"
else
mount | grep -o 'on /var/lib/kubelet.* type' | cut -c 4- | rev | cut -c 6- | rev | sort -r | xargs --no-run-if-empty sudo umount
sudo rm -Rf /var/lib/kubelet
sudo mkdir -p /var/lib/kubelet
sudo mount --bind /var/lib/kubelet /var/lib/kubelet
sudo mount --make-shared /var/lib/kubelet
cp -r "$this_dir/manifests-multi/" "$DOCKER_MACHINE_NAME:/etc/kubernetes"
fi
if [[ -f "$HOME/.docker/config.json" ]]; then
private_repo_creds_mount="--volume=\"$HOME/.docker:/root/.docker\""
else
echo "Warning: Docker registry credentials not found, private registries disabled."
private_repo_creds_mount=""
fi
echo "Starting kubelet"
docker run \
--name=kubelet \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:rw \
--volume=/var/run:/var/run:rw \
--volume=/var/lib/kubelet:/var/lib/kubelet:shared \
--volume=/etc/kubernetes/manifests-multi:/etc/kubernetes/manifests-multi \
$private_repo_creds_mount \
--net=host \
--pid=host \
--privileged=true \
-d \
gcr.io/google_containers/hyperkube-amd64:v1.3.9 \
/hyperkube kubelet \
--hostname-override="127.0.0.1" \
--address="0.0.0.0" \
--api-servers=http://localhost:8080 \
--config=/etc/kubernetes/manifests-multi \
--cluster-dns=10.0.0.10 \
--cluster-domain=cluster.local \
--allow-privileged=true --v=2 >/dev/null 2>&1
echo "Waiting for Kubernetes cluster to become available..."
until $(kubectl cluster-info &> /dev/null); do
sleep 1
done
echo "Kubernetes cluster is up."