Skip to content

Commit b3a3391

Browse files
Added scripts to bootstrap cluster without LB, added persistent storage, added vscode ide container, exposed vscode with ingress
1 parent d1297b7 commit b3a3391

File tree

5 files changed

+143
-36
lines changed

5 files changed

+143
-36
lines changed

gitter.env.sample

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#CONSOLE https://developer.gitter.im/apps/new
2+
#REDIRECT URL https://gitter.waw.training.csol.cloud/login/callback
3+
4+
export GITTER_OAUTH_KEY=xx
5+
export GITTER_OAUTH_SECRET=xx
6+

ingress_istio.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: istio
5+
namespace: istio-system
6+
spec:
7+
rules:
8+
- host: grafana.waw.training.csol.cloud
9+
http:
10+
paths:
11+
- backend:
12+
serviceName: grafana
13+
servicePort: 3000
14+
- host: prometheus.waw.training.csol.cloud
15+
http:
16+
paths:
17+
- backend:
18+
serviceName: prometheus
19+
servicePort: 9090
20+
- host: kiali.waw.training.csol.cloud
21+
http:
22+
paths:
23+
- backend:
24+
serviceName: kiali
25+
servicePort: 20001
26+
27+

setup_gitter.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/bin/bash
22

3-
#
3+
##
4+
#
5+
# Don't forget to create/update gitter.env file
6+
# and update gitter room
7+
#
8+
##
49
export workshopNamespace=workshop
510
export gitterRoom="ContainerSolutions/warsaw-workshop"
611

setup_infra.sh

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
PROJECT_ID=${PROJECT_ID:-"container-solutions-workshops"}
2-
CLUSTER_NAME=${CLUSTER_NAME:-"workshop"}
2+
CLUSTER_NAME=${CLUSTER_NAME:-"workshop-marek-2"}
33
ZONE=${ZONE:-"europe-west3-b"}
44

55
gcloud beta container \
66
--project "${PROJECT_ID}" \
77
clusters create "${CLUSTER_NAME}" \
88
--zone "${ZONE}" \
99
--username "admin" \
10-
--machine-type "n1-standard-4" \
10+
--machine-type "n1-standard-2" \
1111
--image-type "UBUNTU" \
1212
--disk-type "pd-standard" \
1313
--disk-size "100" \
1414
--metadata disable-legacy-endpoints=true \
1515
--scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
1616
--num-nodes "3" \
17-
--enable-cloud-logging \
18-
--enable-cloud-monitoring \
17+
--no-enable-cloud-logging \
18+
--no-enable-cloud-monitoring \
1919
--no-enable-ip-alias \
2020
--network "projects/container-solutions-workshops/global/networks/default" \
21-
--addons HorizontalPodAutoscaling \
21+
--addons HorizontalPodAutoscaling,Istio \
2222
--no-enable-autoupgrade \
23-
--enable-autorepair
24-
#cloud beta container \
25-
# --project "container-solutions-workshops" \
26-
# node-pools create "pool-1" \
27-
# --cluster "workshop" \
28-
# --machine-type "n1-standard-2" \
29-
# --image-type "UBUNTU" \
30-
# --disk-type "pd-standard" \
31-
# --disk-size "100" \
32-
# --metadata disable-legacy-endpoints=true \
33-
# --scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
34-
# --preemptible \
35-
# --num-nodes "3" \
36-
# --no-enable-autoupgrade \
37-
# --enable-autorepairi \
38-
# --zone "europe-west3-b"
23+
--enable-autorepair
24+
25+
gcloud container clusters get-credentials "${CLUSTER_NAME}" --project "${PROJECT_ID}" --zone "${ZONE}"

workshop-functions.sh

+96-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,38 @@ metadata:
1818
---
1919
kind: Role
2020
apiVersion: rbac.authorization.k8s.io/v1beta1
21+
metadata:
22+
name: role-${namespace}
23+
namespace: istio-system
24+
labels:
25+
user: "${namespace}"
26+
rules:
27+
- apiGroups: [""]
28+
resources:
29+
- services
30+
- pods
31+
verbs:
32+
- get
33+
- list
34+
---
35+
kind: RoleBinding
36+
apiVersion: rbac.authorization.k8s.io/v1beta1
37+
metadata:
38+
name: rb-${namespace}
39+
namespace: istio-system
40+
labels:
41+
user: "${namespace}"
42+
subjects:
43+
- kind: ServiceAccount
44+
name: sa-${namespace}
45+
namespace: ${workshopNamespace}
46+
roleRef:
47+
apiGroup: rbac.authorization.k8s.io
48+
kind: Role
49+
name: role-${namespace}
50+
---
51+
kind: Role
52+
apiVersion: rbac.authorization.k8s.io/v1beta1
2153
metadata:
2254
name: role-${namespace}
2355
namespace: ${namespace}
@@ -103,6 +135,7 @@ namespace() {
103135

104136
kubectl create ns ${namespace}
105137
kubectl label ns ${namespace} user=${namespace}
138+
kubectl label ns ${namespace} istio-injection=enabled
106139
assign-role-to-ns ${namespace} | kubectl create -f -
107140

108141
kubectl create clusterrolebinding crb-${namespace} --clusterrole=lister --serviceaccount=${workshopNamespace}:sa-${namespace}
@@ -140,6 +173,21 @@ depl() {
140173
local name=${namespace}
141174

142175
cat <<EOF
176+
---
177+
apiVersion: v1
178+
kind: PersistentVolumeClaim
179+
metadata:
180+
labels:
181+
user: "${namespace}"
182+
run: ${name}
183+
name: ${name}-pvc
184+
spec:
185+
accessModes:
186+
- ReadWriteOnce
187+
resources:
188+
requests:
189+
storage: 512M
190+
---
143191
apiVersion: apps/v1beta1
144192
kind: Deployment
145193
metadata:
@@ -159,17 +207,36 @@ spec:
159207
spec:
160208
serviceAccountName: sa-${name}
161209
volumes:
210+
- name: storage
211+
persistentVolumeClaim:
212+
claimName: ${name}-pvc
162213
- name: gitrepo
163214
gitRepo:
164215
repository: ${gitrepo}
165216
directory: .
217+
initContainers:
218+
- name: copy-repo-to-storage
219+
image: busybox:1.28
220+
command: ['sh', '-c', 'cp -rf /tmp/repo /tmp/storage && chown -R 1000:1000 /tmp/storage']
221+
volumeMounts:
222+
- mountPath: /tmp/repo
223+
name: gitrepo
224+
- mountPath: /tmp/storage
225+
name: storage
166226
containers:
227+
- image: codercom/code-server:v2
228+
args:
229+
- "--auth=none"
230+
- "--port=8181"
231+
name: vscode
232+
volumeMounts:
233+
- mountPath: /home/coder/workshop
234+
name: storage
167235
- args:
168236
- gotty
169237
- "-w"
170238
- "--credential=user:${sessionSecret}"
171239
- "--title-format=${name}"
172-
#- tmux
173240
- bash
174241
env:
175242
- name: NS
@@ -190,7 +257,7 @@ spec:
190257
name: dev
191258
volumeMounts:
192259
- mountPath: /root/workshop
193-
name: gitrepo
260+
name: storage
194261
---
195262
apiVersion: v1
196263
kind: Service
@@ -201,9 +268,14 @@ metadata:
201268
name: ${name}
202269
spec:
203270
ports:
204-
- port: 8080
271+
- name: shell
272+
port: 8080
205273
protocol: TCP
206274
targetPort: 8080
275+
- name: ide
276+
port: 8181
277+
protocol: TCP
278+
targetPort: 8181
207279
selector:
208280
run: ${name}
209281
type: NodePort
@@ -212,13 +284,21 @@ apiVersion: extensions/v1beta1
212284
kind: Ingress
213285
metadata:
214286
annotations:
287+
nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
288+
nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
215289
nginx.org/websocket-services: ${name}
216290
labels:
217291
user: "${namespace}"
218292
name: ${name}
219293
spec:
220294
rules:
221-
- host: ${name}.${domain}
295+
- host: ide.${name}.${domain}
296+
http:
297+
paths:
298+
- backend:
299+
serviceName: ${name}
300+
servicePort: 8181
301+
- host: shell.${name}.${domain}
222302
http:
223303
paths:
224304
- backend:
@@ -268,19 +348,21 @@ get-url() {
268348
declare deployment=${1}
269349

270350
: ${deployment:? required}
351+
pod=$(kubectl get po -lrun=${deployment} -o jsonpath='{.items[0].metadata.name}')
271352

272-
sessionUrl=http://${deployment}.${domain}/
273-
kubectl annotate deployments ${deployment} --overwrite sessionurl="${sessionUrl}"
353+
sessionurl=$(kubectl get deployments. ${deployment} -o jsonpath='{.metadata.annotations.sessionurl}')
354+
newSessionUrl="${sessionurl%/*/}"
355+
kubectl annotate deployments ${deployment} --overwrite sessionurl="${newSessionUrl}"
274356

275357
externalip=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type == "ExternalIP")].address}')
276-
nodePort=$(kubectl get svc ${deployment} -o jsonpath="{.spec.ports[0].nodePort}")
277-
sessionUrlNodePort="http://${externalip}:${nodePort}${rndPath}"
278-
kubectl annotate deployments ${deployment} --overwrite sessionurlnp=${sessionUrlNodePort}
358+
nodePortShell=$(kubectl get svc ${deployment} -o jsonpath="{.spec.ports[0].nodePort}")
359+
nodePortIde=$(kubectl get svc ${deployment} -o jsonpath="{.spec.ports[1].nodePort}")
360+
sessionUrlNodePort="http://${externalip}:${nodePortShell}"
361+
sessionUrlNodePortIde="http://${externalip}:${nodePortIde}"
362+
kubectl annotate deployments ${deployment} --overwrite sessionurlnp=${nodePortShell}
279363

280-
echo "open ${sessionUrlNodePort}"
281-
echo "open ${sessionUrl}"
282-
283-
}
364+
echo "open shell ${sessionUrlNodePort}"
365+
echo "open ide ${sessionUrlNodePortIde}"
284366

285367
switchNs() {
286368
actualNs=$(kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}')
@@ -378,7 +460,7 @@ clean-user() {
378460
ns=$1;
379461
: ${ns:?required};
380462

381-
kubectl delete all,ns,sa,clusterrolebinding,ing -l "user in (${ns},${ns}play)"
463+
kubectl delete all,ns,sa,clusterrolebinding,ing,pv,pvc -l "user in (${ns},${ns}play)"
382464
}
383465

384466
list-sessions() {

0 commit comments

Comments
 (0)