-
Notifications
You must be signed in to change notification settings - Fork 8
/
add-kube-node.sh
executable file
·93 lines (76 loc) · 2.26 KB
/
add-kube-node.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
#!/bin/bash
set -e
# Add node to existing CLC kubernetes cluster
# Usage info
function show_help() {
cat << EOF
Usage: ${0##*/} [OPTIONS]
Create servers in the CenturyLinkCloud environment and add to an
existing CLC kubernetes cluster
Environment variables CLC_V2_API_USERNAME and CLC_V2_API_PASSWD must be set in
order to access the CenturyLinkCloud API
-h (--help) display this help and exit
-c= (--clc_cluster_name=) set the name of the cluster, as used in CLC group names
-m= (--minion_count=) number of kubernetes minion nodes to add
EOF
}
function exit_message() {
echo "ERROR: $1" >&2
exit 1
}
# set count=1 as default
minion_count=1
for i in "$@"
do
case $i in
-h|--help)
show_help && exit 0
;;
-c=*|--clc_cluster_name=*)
CLC_CLUSTER_NAME="${i#*=}"
shift # past argument=value
;;
-m=*|--minion_count=*)
minion_count="${i#*=}"
shift # past argument=value
;;
*)
echo "Unknown option: $1"
echo
show_help
exit 1
;;
esac
done
if [ -z ${CLC_V2_API_USERNAME:-} ] || [ -z ${CLC_V2_API_PASSWD:-} ]
then
exit_message 'Environment variables CLC_V2_API_USERNAME, CLC_V2_API_PASSWD must be set'
fi
if [ -z ${CLC_CLUSTER_NAME} ]
then
exit_message 'Cluster name must be set with either command-line argument or as environment variable CLC_CLUSTER_NAME'
fi
CLC_CLUSTER_HOME=~/.clc_kube/${CLC_CLUSTER_NAME}
hosts_dir=${CLC_CLUSTER_HOME}/hosts/
config_dir=${CLC_CLUSTER_HOME}/config/
if [ ! -d ${config_dir} ]
then
exit_message "Configuration directory ${config_dir} not found"
fi
cd ansible
# set the _add_nodes_ variable
ansible-playbook create-minion-hosts.yml \
-e add_nodes=1 \
-e minion_count=$minion_count \
-e config_vars_master=${CLC_CLUSTER_HOME}/config/master_config.yml \
-e config_vars_minion=${CLC_CLUSTER_HOME}/config/minion_config.yml
#### verify access
echo ansible -i $hosts_dir -m shell -a uptime all
ansible -i $hosts_dir -m shell -a uptime all
echo $hosts_dir
#### Part3
echo "Part3 - Setting up kubernetes"
ansible-playbook install_kubernetes.yml -i $hosts_dir \
-e config_vars_master=${CLC_CLUSTER_HOME}/config/master_config.yml \
-e config_vars_minion=${CLC_CLUSTER_HOME}/config/minion_config.yml \
--limit kube-node