-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathup.sh
More file actions
executable file
·58 lines (46 loc) · 1.72 KB
/
up.sh
File metadata and controls
executable file
·58 lines (46 loc) · 1.72 KB
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
#!/usr/bin/env bash
function help {
echo "Usage: ./up.sh STACK_NAME"
echo ""
echo "Flags:"
echo " --only-provision Skips bringing up infrastructure and only runs Kubespray provisioner"
}
function checkForError {
if [[ $1 -gt 0 ]]; then
echo "Error: $2. Aborting..."
exit 1
fi
}
if [[ -z "$1" ]]; then
help
exit 1
fi
if [[ ! $(pulumi stack --show-name) == "$1" ]]; then
echo "Changing to stack $1..."
pulumi stack select $1
checkForError $? "invalid Stack specified"
fi
echo "$2"
if [[ ! "$2" == "--only-provision" ]]; then
# echo "Bringing up cluster..."
# pulumi up -y
checkForError $? "failed bringing up cluster infrastrucure, cluster may be in an incomplete state"
fi
name=$(pulumi stack output cluster | jq -r .name)
env_name=$(pulumi stack output environment | jq -r .name)
master=$(pulumi stack output cluster | jq -r .masters[0])
echo "Pulling down kubespray..."
rm -rf /tmp/kubespray &> /dev/null
git clone https://github.com/kubernetes-sigs/kubespray /tmp/kubespray
echo "Copying inventory over..."
cp -r inv/${env_name} /tmp/kubespray/inventory
echo "Creating inventory file..."
pulumi stack output cluster | python inv.py > /tmp/kubespray/inventory/${env_name}/inventory.ini
checkForError $? "failed generating Ansible inventory"
echo "Configuring cluster..."
ansible-playbook -i /tmp/kubespray/inventory/${env_name}/inventory.ini --become --become-user=root /tmp/kubespray/cluster.yml
checkForError "failed provisioning the cluster, it may be in an incomplete state"
echo "Pulling down kube config..."
mkdir -p ~/.kube/custom-contexts/${name}
ssh -t josh@${master} "sudo cat /etc/kubernetes/admin.conf" > ~/.kube/custom-contexts/${name}/config.yml
echo "Done!"