-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudinit.sh
More file actions
261 lines (189 loc) · 5.88 KB
/
Copy pathcloudinit.sh
File metadata and controls
261 lines (189 loc) · 5.88 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
#adding comments to make code readable
set -o pipefail
LOG_FILE="/var/log/Wandb-initialize.log"
log() {
echo "$(date) [${EXECNAME}]: $*" >> "${LOG_FILE}"
}
region=`curl -s -H "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/regionInfo/regionIdentifier`
load_balancer_ip=`curl -s -H "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v2/instance/metadata/load_balancer_ip`
oke_cluster_id=`curl -s -H "Authorization: Bearer Oracle" -L http://169.254.169.254/opc/v1/instance/metadata/oke_cluster_id`
country=`echo $region|awk -F'-' '{print $1}'`
city=`echo $region|awk -F'-' '{print $2}'`
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key
EOF
yum install kubectl git -y >> $LOG_FILE
mkdir -p /home/opc/.kube
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "alias k='kubectl'" >> ~/.bashrc
echo "source <(kubectl completion bash)" >> /home/opc/.bashrc
echo "alias k='kubectl'" >> /home/opc/.bashrc
source ~/.bashrc
yum install python36-oci-cli -y >> $LOG_FILE
echo "export OCI_CLI_AUTH=instance_principal" >> ~/.bash_profile
echo "export OCI_CLI_AUTH=instance_principal" >> ~/.bashrc
echo "export OCI_CLI_AUTH=instance_principal" >> /home/opc/.bash_profile
echo "export OCI_CLI_AUTH=instance_principal" >> /home/opc/.bashrc
while [ ! -f /root/.kube/config ]
do
sleep 5
source ~/.bashrc
oci ce cluster create-kubeconfig --cluster-id ${oke_cluster_id} --file /root/.kube/config --region ${region} --token-version 2.0.0 >> $LOG_FILE
done
cp /root/.kube/config /home/opc/.kube/config
chown -R opc:opc /home/opc/.kube/
mkdir -p /opt/WandB
cd /opt/Wandb
cat <<EOF | tee /opt/WandB/wandb_namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: wandb
EOF
kubectl --kubeconfig /root/.kube/config create -f /opt/WandB/wandb_namespace.yaml
LBIP=$load_balancer_ip
DOMAIN="wandb.${LBIP}.nip.io"
mkdir -p /opt/LB_certs
cd /opt/LB_certs
openssl req -x509 -sha256 -days 356 -nodes -newkey rsa:2048 -subj "/CN=${DOMAIN}/C=$country/L=$city" -keyout rootCA.key -out rootCA.crt
cat > csr.conf <<EOF
[ req ]
default_bits = 2048
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn
[ dn ]
C = $country
ST = $city
L = $city
O = WandB
OU = WandB
CN = ${DOMAIN}
[ req_ext ]
subjectAltName = @alt_names
[ alt_names ]
DNS.1 = ${DOMAIN}
IP.1 = ${LBIP}
EOF
openssl genrsa -out "${DOMAIN}.key" 2048
openssl req -new -key "${DOMAIN}.key" -out "${DOMAIN}.csr" -config csr.conf
cat > cert.conf <<EOF
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = ${DOMAIN}
IP.1 = ${LBIP}
EOF
openssl x509 -req -in "${DOMAIN}.csr" -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out "${DOMAIN}.crt" -days 365 -sha256 -extfile cert.conf
kubectl --kubeconfig /root/.kube/config create secret tls wandb-tls-cert --key=$DOMAIN.key --cert=$DOMAIN.crt -n wandb
cat <<EOF | tee /opt/WandB/wandb_deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wandb
namespace: wandb
spec:
selector:
matchLabels:
app: wandb
template:
metadata:
labels:
app: wandb
spec:
containers:
- name: wandb
image: wandb/local
resources:
limits:
memory: "1G"
cpu: "500m"
ports:
- containerPort: 8080
EOF
kubectl --kubeconfig /root/.kube/config apply -f /opt/WandB/wandb_deploy.yaml
sleep 30
cat <<EOF | tee /opt/WandB/wandb_api_service.yaml
apiVersion: v1
kind: Service
metadata:
name: wandb-api-service
namespace: wandb
spec:
selector:
app: wandb
ports:
- port: 8080
targetPort: 8080
protocol: TCP
name: api
EOF
kubectl --kubeconfig /root/.kube/config apply -f /opt/WandB/wandb_api_service.yaml
kubectl --kubeconfig /root/.kube/config apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.2/deploy/static/provider/cloud/deploy.yaml
sleep 30
kubectl --kubeconfig /root/.kube/config delete svc ingress-nginx-controller -n ingress-nginx
cat <<EOF | tee /opt/WandB/nginx_service.yaml
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx-controller
namespace: ingress-nginx
labels:
nginx: ingressgateway
annotations:
oci.oraclecloud.com/load-balancer-type: "lb"
service.beta.kubernetes.io/oci-load-balancer-backend-protocol: "TCP"
service.beta.kubernetes.io/oci-load-balancer-shape: "flexible"
service.beta.kubernetes.io/oci-load-balancer-shape-flex-min: "10"
service.beta.kubernetes.io/oci-load-balancer-shape-flex-max: "10"
spec:
type: LoadBalancer
loadBalancerIP: $load_balancer_ip
selector:
app.kubernetes.io/name: ingress-nginx
ports:
- name: https
port: 443
targetPort: 443
- name: http
port: 80
targetPort: 80
EOF
kubectl --kubeconfig /root/.kube/config apply -f /opt/WandB/nginx_service.yaml
cat <<EOF | tee /opt/WandB/wandb_api_ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wandb-api-ingress
namespace: wandb
spec:
ingressClassName: nginx
tls:
- hosts:
- "$DOMAIN"
secretName: wandb-tls-cert
rules:
- host: "$DOMAIN"
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: wandb-api-service
port:
number: 8080
EOF
kubectl --kubeconfig /root/.kube/config apply -f /opt/WandB/wandb_api_ingress.yaml
echo "Load Balancer IP is ${LBIP}" |tee -a $LOG_FILE
echo "Point your browser to https://${DOMAIN}" |tee -a $LOG_FILE