forked from nuvolaris/nuvolaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·81 lines (76 loc) · 2.47 KB
/
init.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
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# This script performs initializations, creating a kind clusters
# that works either inside or outside of a container.
#
# check kind is in path
if ! which kind >/dev/null
then echo "Please install Kind from https://kind.sigs.k8s.io/docs/user/quick-start/#installation"
exit 1
fi
# you are requesting a rebuild
if test "$1" == "reset"
then kind delete clusters nuvolaris
fi
if test "$1" != ""
then echo "use either no arguments to create a cluster or 'reset' to rebuild it"
exit 1
fi
# setup env for contaner
KIND=kind
if [ -f /.dockerenv ] && [ -S /var/run/docker-host.sock ]
then KIND="sudo env DOCKER_HOST=unix:///var/run/docker-host.sock kind"
fi
# if the nuvolaris cluster already running export its configuration
if $KIND get clusters | grep nuvolaris >/dev/null 2>/dev/null
then $KIND export kubeconfig --name nuvolaris
else
# create cluster
cat <<EOF | $KIND create cluster --wait=1m --name=nuvolaris --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
extraPortMappings:
- containerPort: 30232
hostPort: 3232
protocol: TCP
- containerPort: 30233
hostPort: 3233
protocol: TCP
- containerPort: 30896
hostPort: 7896
protocol: TCP
EOF
fi
# we are in docker
if test -f /.dockerenv
then
# copy the kubeconfig
mkdir -p /home/nuvolaris/.kube
sudo cp /root/.kube/config /home/nuvolaris/.kube/config
sudo chown nuvolaris:nuvolaris /home/nuvolaris/.kube/config
# proxy to sockerhost and loop forever if not yet there
if ! test -S /var/run/docker-host.sock
then exec sudo /usr/bin/socat \
UNIX-LISTEN:/var/run/docker.sock,fork,mode=660,user=nuvolaris \
UNIX-CONNECT:/var/run/docker-host.sock
fi
fi