-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy.sh
executable file
·101 lines (89 loc) · 3.63 KB
/
deploy.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
#!/usr/local/bin/bash
# Script used to deploy infrastructure for Kubernetes, and test and tear down as configured
date
# Turn prompting for ssh key off
echo "StrictHostKeyChecking no" > ~/.ssh/config
# Commands to run after each step script, if any
declare -A CMDS
CMDS["00-config.sh"]=""
CMDS["01-provision-instances.sh"]="grep 'is running ' 01-provision-instances.sh.log | egrep '^Instance'"
CMDS["02-certs.sh"]=""
CMDS["02-use_kubeadm-initialize.sh"]=""
CMDS["02-use_kubeadm-kubelet-setup.sh"]=""
CMDS["02-use_kubeadm_install_cluster.sh"]="echo 'NODES and PODs:'; tail -30 02-use_kubeadm_install_cluster.sh.log | egrep -A 30 'kubectl get nodes; kubectl get pods'"
CMDS["03-generate-config-files.sh"]=""
CMDS["04-encryption-keys.sh"]=""
CMDS["05-bootstrapping-etcd.sh"]=""
CMDS["05-bootstrapping-etcd_on-controller.sh"]=""
CMDS["06-bootstrapping-control-plane.sh"]=""
CMDS["06-bootstrapping-control-plane_on-controller.sh"]=""
CMDS["06-bootstrapping-control-plane_on-controller0.sh"]=""
CMDS["07-bootstrapping-worker-nodes.sh"]=""
CMDS["07-bootstrapping-worker-nodes_on-worker.sh"]=""
CMDS["08-kubectl-remote-access.sh"]=""
CMDS["09-pod-network-routes.sh"]=""
CMDS["10-dns-addon.sh"]=""
CMDS["11-e2e-tests.sh"]=""
CMDS["11-e2e-tests_on-controller-kubetest.sh"]=""
CMDS["11-e2e-tests_on-controller.sh"]=""
CMDS["11-smoke-tests.sh"]=""
CMDS["11-smoke-tests_on-controller.sh"]=""
CMDS["12-cleanup.sh"]=""
# Get and run initial configuration
bash 00-config.sh
. set-var.sh
#Select install with Kubeadm or method specified in config
if [ "$CLUSTER_INSTALL_METHOD" = "HARD_WAY" ]; then
STEP_SCRIPTS="01-provision-instances.sh 02-certs.sh 03-generate-config-files.sh 04-encryption-keys.sh 05-bootstrapping-etcd.sh 06-bootstrapping-control-plane.sh 07-bootstrapping-worker-nodes.sh 08-kubectl-remote-access.sh 09-pod-network-routes.sh 10-dns-addon.sh "
elif [ "$CLUSTER_INSTALL_METHOD" = "KUBEADM" -o "$INSTALL_K8S_ONLY" = "YES" ]; then
STEP_SCRIPTS="01-provision-instances.sh 02-use_kubeadm_install_cluster.sh "
else
STEP_SCRIPTS="01-provision-instances.sh"
fi
# Select which tests to run
if [ ! -z "$STEP_SCRIPTS" -a "$CLUSTER_INSTALL_METHOD" = "KUBEADM" ]; then
if [ "$WHICH_TESTS" = "SMOKE" ]; then
STEP_SCRIPTS+=" 11-smoke-tests.sh "
elif [ "$WHICH_TESTS" = "SMOKE_AND_E2E" ]; then
STEP_SCRIPTS+=" 11-smoke-tests.sh 11-e2e-tests.sh"
fi
fi
# Select whether to cleanup or not
if [ -n "${CLEANUP}" -a "${CLEANUP}" -eq 1 ]; then
echo "Note: resources will be automatically deleted after deployment."
STEP_SCRIPTS+=" 12-cleanup.sh"
else
echo "Note: resources will be left up after deployment. To cleanup, run teardown.sh."
fi
echo "Running the following scripts: ${STEP_SCRIPTS}"
echo "Starting deployment, configuration and validation of Kubernetes cluster."
# Run each script in steps needed
for SCRIPT in $STEP_SCRIPTS
do
echo "================================================================"
echo "RUNNING $SCRIPT"
bash -xv $SCRIPT > "${SCRIPT}.log" 2>&1
RETVAL=$?
if [ ! -z "${CMDS[${SCRIPT}]}" ]; then
eval "${CMDS[${SCRIPT}]}" # show results from script
fi
ls -lh "${SCRIPT}.log"
if [ "${SCRIPT}" = "01-provision-instances.sh" ]; then
. set-var.sh
fi
if [ $RETVAL -ne 0 ]; then # If script failed, note it and recover appropriately
echo "ERROR: $SCRIPT Failed. See ${SCRIPT} for details. "
if [ -n "${CLEANUP}" -a "${CLEANUP}" -eq 1 ]; then
echo "Cleaning up resources and exiting now."
bash -xv 12-cleanup.sh > 12-cleanup.sh.log 2>&1
else
echo "Exiting now. Resources will stay up for troubleshooting."
break
fi
break
fi
done
echo "Done."
# Turn prompting for ssh key back on
rm -f ~/.ssh/config *.json *.kubeconfig *.yaml crt.txt
date