@@ -18,6 +18,38 @@ metadata:
18
18
---
19
19
kind: Role
20
20
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
21
53
metadata:
22
54
name: role-${namespace}
23
55
namespace: ${namespace}
@@ -103,6 +135,7 @@ namespace() {
103
135
104
136
kubectl create ns ${namespace}
105
137
kubectl label ns ${namespace} user=${namespace}
138
+ kubectl label ns ${namespace} istio-injection=enabled
106
139
assign-role-to-ns ${namespace} | kubectl create -f -
107
140
108
141
kubectl create clusterrolebinding crb-${namespace} --clusterrole=lister --serviceaccount=${workshopNamespace} :sa-${namespace}
@@ -140,6 +173,21 @@ depl() {
140
173
local name=${namespace}
141
174
142
175
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
+ ---
143
191
apiVersion: apps/v1beta1
144
192
kind: Deployment
145
193
metadata:
@@ -159,17 +207,36 @@ spec:
159
207
spec:
160
208
serviceAccountName: sa-${name}
161
209
volumes:
210
+ - name: storage
211
+ persistentVolumeClaim:
212
+ claimName: ${name} -pvc
162
213
- name: gitrepo
163
214
gitRepo:
164
215
repository: ${gitrepo}
165
216
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
166
226
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
167
235
- args:
168
236
- gotty
169
237
- "-w"
170
238
- "--credential=user:${sessionSecret} "
171
239
- "--title-format=${name} "
172
- #- tmux
173
240
- bash
174
241
env:
175
242
- name: NS
@@ -190,7 +257,7 @@ spec:
190
257
name: dev
191
258
volumeMounts:
192
259
- mountPath: /root/workshop
193
- name: gitrepo
260
+ name: storage
194
261
---
195
262
apiVersion: v1
196
263
kind: Service
@@ -201,9 +268,14 @@ metadata:
201
268
name: ${name}
202
269
spec:
203
270
ports:
204
- - port: 8080
271
+ - name: shell
272
+ port: 8080
205
273
protocol: TCP
206
274
targetPort: 8080
275
+ - name: ide
276
+ port: 8181
277
+ protocol: TCP
278
+ targetPort: 8181
207
279
selector:
208
280
run: ${name}
209
281
type: NodePort
@@ -212,13 +284,21 @@ apiVersion: extensions/v1beta1
212
284
kind: Ingress
213
285
metadata:
214
286
annotations:
287
+ nginx.ingress.kubernetes.io/proxy-send-timeout: "3600"
288
+ nginx.ingress.kubernetes.io/proxy-read-timeout: "3600"
215
289
nginx.org/websocket-services: ${name}
216
290
labels:
217
291
user: "${namespace} "
218
292
name: ${name}
219
293
spec:
220
294
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}
222
302
http:
223
303
paths:
224
304
- backend:
@@ -268,19 +348,21 @@ get-url() {
268
348
declare deployment=${1}
269
349
270
350
: ${deployment:? required}
351
+ pod=$( kubectl get po -lrun=${deployment} -o jsonpath=' {.items[0].metadata.name}' )
271
352
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} "
274
356
275
357
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}
279
363
280
- echo " open ${sessionUrlNodePort} "
281
- echo " open ${sessionUrl} "
282
-
283
- }
364
+ echo " open shell ${sessionUrlNodePort} "
365
+ echo " open ide ${sessionUrlNodePortIde} "
284
366
285
367
switchNs () {
286
368
actualNs=$( kubectl config view --minify -o jsonpath=' {.contexts[0].context.namespace}' )
@@ -378,7 +460,7 @@ clean-user() {
378
460
ns=$1 ;
379
461
: ${ns:? required} ;
380
462
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)"
382
464
}
383
465
384
466
list-sessions () {
0 commit comments