forked from NVIDIA/deepops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy_rook.sh
executable file
·198 lines (159 loc) · 6.45 KB
/
deploy_rook.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/usr/bin/env bash
# Upgrading:
# `helm update`
# `helm search rook` # get latest version number
# `helm upgrade --namespace rook-ceph rook-ceph rook-release/rook-ceph --version v0.9.0-174.g3b14e51`
# Get absolute path for script and root
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
ROOT_DIR="${SCRIPT_DIR}/../.."
CHART_VERSION="1.22.1"
HELM_ROOK_CHART_REPO="${HELM_ROOK_CHART_REPO:-https://charts.rook.io/release}"
HELM_ROOK_CHART_VERSION="${HELM_ROOK_CHART_VERSION:-v1.1.1}"
# Allow overriding config dir to look in
DEEPOPS_CONFIG_DIR=${DEEPOPS_CONFIG_DIR:-"${ROOT_DIR}/config"}
# Default creds to create
DEEPOPS_ROOK_USER="${DEEPOPS_ROOK_USER:-admin}"
DEEPOPS_ROOK_PASS="${DEEPOPS_ROOK_PASS:-deepops}"
# Setting to set Rook as default or non-default storageclass
DEEPOPS_ROOK_SC_NAME="${DEEPOPS_ROOK_SC_NAME:-rook-ceph-block}"
DEEPOPS_ROOK_NO_DEFAULT="${DEEPOPS_ROOK_NO_DEFAULT:-}"
if [ ! -d "${DEEPOPS_CONFIG_DIR}" ]; then
echo "Can't find configuration in ${DEEPOPS_CONFIG_DIR}"
echo "Please set DEEPOPS_CONFIG_DIR env variable to point to config location"
exit 1
fi
echo "DEPRECATION NOTICE: This script is deprecated with no support and not guaranteed to work"
function help_me() {
echo "Usage:"
echo "-h This message."
echo "-p Print out the connection info for Rook-Ceph."
echo "-d Delete Rook from your system (this delete any created volumes)."
echo "-w Poll for rook-ceph to reach a healthy and initialized state."
echo "-u Create a new dashboard user (default username: 'admin' password: 'deepops', set with env variables DEEPOPS_ROOK_USER/DEEPOPS_ROOK_PASS)."
echo "-x Install Rook-Ceph, but do not set it as the Default StorageClass."
}
function poll_ceph() {
echo "Beginning to poll for Ceph and Rook setup completion."
echo "This may throw several errors and take up to 10 minutes. This behavior is expected."
echo "The script will stop polling when Ceph setup is completed and the cluster is in a healthy state".
echo ""; echo ""; echo ""
while true; do
rook_tools_pod=$(kubectl -n rook-ceph get pod -l app=rook-ceph-tools -o name | cut -d \/ -f2 | sed -e 's/\\r$//g')
kubectl -n rook-ceph exec -ti $rook_tools_pod -- ceph status # Run once to print output
kubectl -n rook-ceph exec -ti $rook_tools_pod -- ceph status | grep "mds: cephfs" | grep "up:active" | grep "standby-replay" # Run again to check for completion
if [ "${?}" == "0" ]; then
echo "Ceph has completed setup."
break
fi
sleep 15
done
}
function delete_rook() {
kubectl delete -f workloads/services/k8s/rook-cluster.yml
helm delete rook-ceph
kubectl -n rook-ceph delete cephcluster rook-ceph
kubectl -n rook-ceph delete storageclass rook-ceph-block
kubectl delete ns rook-ceph-system
kubectl delete ns rook-ceph
ansible k8s-cluster -b -m file -a "path=/var/lib/rook state=absent"
}
function print_rook() {
# Get Rook Ceph Tools POD name
export rook_toolspod=$(kubectl -n rook-ceph get pod -l app=rook-ceph-tools --no-headers -o custom-columns=:.metadata.name)
# Get IP of first master
master_ip=$(kubectl get nodes -l node-role.kubernetes.io/master= --no-headers -o custom-columns=IP:.status.addresses.*.address | cut -f1 -d, | head -1)
# Get Ceph dashboard port
dash_port=$(kubectl -n rook-ceph get svc rook-ceph-mgr-dashboard-external-https --no-headers -o custom-columns=PORT:.spec.ports.*.nodePort)
# Ceph Dashboard
export rook_ceph_dashboard="https://${master_ip}:${dash_port}"
echo
echo "Ceph deployed, it may take up to 10 minutes for storage to be ready"
echo "If install takes more than 30 minutes be sure you have cleaned up any previous Rook installs by running '${0} -d' and have installed the required libraries using the bootstrap-rook.yml playbook"
echo "Monitor readiness with: ${0} -w"
echo
echo "Ceph dashboard: ${rook_ceph_dashboard}"
echo
echo "Create dashboard user with: kubectl -n rook-ceph exec -ti ${rook_toolspod} -- ceph dashboard set-login-credentials <username> <password>"
echo
}
function create_ceph_user() {
# Get Rook Ceph Tools POD name
export rook_toolspod=$(kubectl -n rook-ceph get pod -l app=rook-ceph-tools --no-headers -o custom-columns=:.metadata.name)
kubectl -n rook-ceph exec -ti ${rook_toolspod} -- ceph dashboard set-login-credentials ${DEEPOPS_ROOK_USER} ${DEEPOPS_ROOK_PASS}
}
function get_opts() {
while getopts "uhwdpx" option; do
case $option in
w)
ROOK_CEPH_POLL=true
;;
d)
ROOK_DELETE=true
;;
p)
ROOK_PRINT=true
;;
u)
ROOK_CEPH_USER=true
;;
x)
DEEPOPS_ROOK_NO_DEFAULT="true"
;;
h)
help_me
exit 1
;;
* )
help_me
exit 1
;;
esac
done
}
function install_rook() {
# Install Helm if it is not already installed
${SCRIPT_DIR}/install_helm.sh
if ! kubectl get ns rook-ceph >/dev/null 2>&1 ; then
kubectl create ns rook-ceph
fi
# https://github.com/rook/rook/blob/master/Documentation/helm-operator.md
helm repo add rook-release "${HELM_ROOK_CHART_REPO}"
# We need to dynamically set up Helm args, so let's use an array
helm_install_args=("--namespace" "rook-ceph"
"--version" "${HELM_ROOK_CHART_VERSION}"
)
# Use an alternate image if set
if [ "${ROOK_CEPH_IMAGE_REPO}" ]; then
helm_install_args+=("--set" "image.repository=${ROOK_CEPH_IMAGE_REPO}")
fi
# Install rook-ceph
if ! helm status -n rook-ceph rook-ceph >/dev/null 2>&1 ; then
helm install rook-ceph rook-release/rook-ceph "${helm_install_args[@]}"
fi
if kubectl -n rook-ceph get pod -l app=rook-ceph-tools 2>&1 | grep "No resources found." >/dev/null 2>&1; then
sleep 5
# If we have an alternate registry defined, dynamically substitute it in
if [ "${DEEPOPS_ROOK_DOCKER_REGISTRY}" ]; then
sed "s/image: /image: ${DEEPOPS_ROOK_DOCKER_REGISTRY}\//g" workloads/services/k8s/rook-cluster.yml | kubectl create -f -
else
kubectl create -f workloads/services/k8s/rook-cluster.yml
fi
fi
sleep 5
if [ "${DEEPOPS_ROOK_NO_DEFAULT}" ]; then
kubectl patch StorageClass ${DEEPOPS_ROOK_SC_NAME} -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
fi
print_rook
}
get_opts ${@}
if [ ${ROOK_DELETE} ]; then
delete_rook
elif [ ${ROOK_CEPH_USER} ]; then
create_ceph_user
elif [ ${ROOK_CEPH_POLL} ]; then
poll_ceph
elif [ ${ROOK_PRINT} ]; then
print_rook
else
install_rook
fi