This repository has been archived by the owner on Mar 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathbootstrap-cluster.sh
executable file
·104 lines (84 loc) · 3.06 KB
/
bootstrap-cluster.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
102
103
104
#!/usr/bin/env bash
# Modified with credit to: billimek@github
#
# Running this script is dependent on your Ansible inventory file
# Ensure you have the right IPs and hostnames in the right section
#
#
# @CHANGEME - Update USER to your RPi SSH user
#
USER="devin"
K3S_VERSION="v1.17.3+k3s1"
REPO_ROOT=$(git rev-parse --show-toplevel)
ANSIBLE_INVENTORY="${REPO_ROOT}"/ansible/inventory
need() {
which "$1" &>/dev/null || die "Binary '$1' is missing but required"
}
need "curl"
need "ssh"
need "kubectl"
need "helm"
need "k3sup"
need "ansible-inventory"
need "jq"
K3S_MASTER=$(ansible-inventory -i ${ANSIBLE_INVENTORY} --list | jq -r '.k3s_master[] | @tsv')
K3S_WORKERS=$(ansible-inventory -i ${ANSIBLE_INVENTORY} --list | jq -r '.k3s_worker[] | @tsv')
message() {
echo -e "\n######################################################################"
echo "# ${1}"
echo "######################################################################"
}
k3sMasterNode() {
message "Installing k3s master to ${K3S_MASTER}"
k3sup install --ip "${K3S_MASTER}" \
--k3s-version "${K3S_VERSION}" \
--user "${USER}" \
--k3s-extra-args "--no-deploy servicelb --no-deploy traefik --no-deploy metrics-server --default-local-storage-path /k3s-local-storage"
mkdir -p ~/.kube
mv ./kubeconfig ~/.kube/config
sleep 10
}
ks3WorkerNodes() {
for worker in $K3S_WORKERS; do
message "Joining ${worker} to ${K3S_MASTER}"
k3sup join --ip "${worker}" \
--server-ip "${K3S_MASTER}" \
--k3s-version "${K3S_VERSION}" \
--user "${USER}"
## Does not work :(
#--k3s-extra-args "--node-label role.node.kubernetes.io/worker=worker"
sleep 10
message "Labeling ${worker} as node-role.kubernetes.io/worker=worker"
hostname=$(ansible-inventory -i ${ANSIBLE_INVENTORY} --list | jq -r --arg k3s_worker "$worker" '._meta[] | .[$k3s_worker].hostname')
kubectl label node ${hostname} node-role.kubernetes.io/worker=worker
done
}
installFlux() {
message "Installing flux"
kubectl apply -f "${REPO_ROOT}"/deployments/flux/namespace.yaml
helm repo add fluxcd https://charts.fluxcd.io
helm repo update
helm upgrade --install flux --values "${REPO_ROOT}"/deployments/flux/flux/flux-values.yaml --namespace flux fluxcd/flux
helm upgrade --install helm-operator --values "${REPO_ROOT}"/deployments/flux/helm-operator/helm-operator-values.yaml --namespace flux fluxcd/helm-operator
FLUX_READY=1
while [ ${FLUX_READY} != 0 ]; do
echo "Waiting for flux pod to be fully ready..."
kubectl -n flux wait --for condition=available deployment/flux
FLUX_READY="$?"
sleep 5
done
sleep 5
}
addDeployKey() {
# grab output the key
FLUX_KEY=$(kubectl -n flux logs deployment/flux | grep identity.pub | cut -d '"' -f2)
message "Adding the key to github automatically"
"${REPO_ROOT}"/hack/add-repo-key.sh "${FLUX_KEY}"
}
k3sMasterNode
ks3WorkerNodes
installFlux
addDeployKey
sleep 5
message "All done!"
kubectl get nodes -o=wide