Skip to content

Commit 5ed599b

Browse files
author
Liav Weiss (EXT-Nokia)
committed
feat(ws): Define k8s workload manifest for backend component #324
Signed-off-by: Liav Weiss (EXT-Nokia) <[email protected]>
1 parent ca8e94c commit 5ed599b

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-0
lines changed

workspaces/backend/Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,13 @@ $(LOCALBIN):
124124

125125
## Tool Binaries
126126
KUBECTL ?= kubectl
127+
KUSTOMIZE := $(LOCALBIN)/kustomize
127128
ENVTEST ?= $(LOCALBIN)/setup-envtest
128129
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
129130
SWAGGER = $(LOCALBIN)/swag
130131

131132
## Tool Versions
133+
KUSTOMIZE_VERSION ?= v5.5.0
132134
ENVTEST_VERSION ?= release-0.19
133135
GOLANGCI_LINT_VERSION ?= v1.61.0
134136
SWAGGER_VERSION ?= v1.16.4
@@ -148,6 +150,26 @@ golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
148150
$(GOLANGCI_LINT): $(LOCALBIN)
149151
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
150152

153+
154+
##@ deployment
155+
156+
.PHONY: deploy
157+
deploy: kustomize ## Deploy backend to the K8s cluster specified in ~/.kube/config.
158+
cd config/default && $(KUSTOMIZE) edit set image nbv2-backend=${IMG}
159+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
160+
161+
.PHONY: undeploy
162+
undeploy: kustomize ## Undeploy backend from the K8s cluster specified in ~/.kube/config.
163+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=true -f -
164+
165+
166+
##@ Dependencies
167+
168+
.PHONY: kustomize
169+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
170+
$(KUSTOMIZE): $(LOCALBIN)
171+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
172+
151173
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
152174
# $1 - target path with name of binary
153175
# $2 - package url which can be installed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: nbv2-backend
5+
namespace: backend-system
6+
labels:
7+
app: nbv2-backend
8+
app.kubernetes.io/component: backend
9+
app.kubernetes.io/managed-by: kustomize
10+
spec:
11+
replicas: 1
12+
strategy:
13+
type: RollingUpdate
14+
rollingUpdate:
15+
maxUnavailable: 0
16+
maxSurge: 1
17+
selector:
18+
matchLabels:
19+
app: nbv2-backend
20+
app.kubernetes.io/component: backend
21+
app.kubernetes.io/managed-by: kustomize
22+
template:
23+
metadata:
24+
labels:
25+
app: nbv2-backend
26+
app.kubernetes.io/component: backend
27+
app.kubernetes.io/managed-by: kustomize
28+
spec:
29+
serviceAccountName: nbv2-backend
30+
securityContext:
31+
runAsNonRoot: true
32+
terminationGracePeriodSeconds: 30
33+
containers:
34+
- name: nbv2-backend
35+
image: nbv2-backend
36+
imagePullPolicy: IfNotPresent
37+
securityContext:
38+
allowPrivilegeEscalation: false
39+
capabilities:
40+
drop:
41+
- "ALL"
42+
ports:
43+
- containerPort: 4000
44+
env:
45+
- name: PORT
46+
value: "4000"
47+
resources:
48+
limits:
49+
cpu: 500m
50+
memory: 256Mi
51+
requests:
52+
cpu: 100m
53+
memory: 128Mi
54+
livenessProbe:
55+
httpGet:
56+
path: /api/v1/healthcheck
57+
port: 4000
58+
scheme: HTTP
59+
initialDelaySeconds: 30
60+
periodSeconds: 20
61+
timeoutSeconds: 5
62+
failureThreshold: 3
63+
successThreshold: 1
64+
readinessProbe:
65+
httpGet:
66+
path: /api/v1/healthcheck
67+
port: 4000
68+
scheme: HTTP
69+
initialDelaySeconds: 10
70+
periodSeconds: 10
71+
timeoutSeconds: 5
72+
failureThreshold: 3
73+
successThreshold: 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- namespace.yaml
6+
- service_account.yaml
7+
- rbac.yaml
8+
- service.yaml
9+
- deployment.yaml
10+
11+
images:
12+
- name: nbv2-backend
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: backend-system
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: ClusterRole
3+
metadata:
4+
name: backend-clusterrole
5+
rules:
6+
- apiGroups:
7+
- kubeflow.org
8+
resources:
9+
- workspaces
10+
- workspacekinds
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- create
16+
- update
17+
- patch
18+
- delete
19+
---
20+
apiVersion: rbac.authorization.k8s.io/v1
21+
kind: ClusterRoleBinding
22+
metadata:
23+
name: backend-clusterrolebinding
24+
roleRef:
25+
apiGroup: rbac.authorization.k8s.io
26+
kind: ClusterRole
27+
name: backend-clusterrole
28+
subjects:
29+
- kind: ServiceAccount
30+
name: nbv2-backend
31+
namespace: backend-system
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: nbv2-backend
5+
namespace: backend-system
6+
labels:
7+
app: nbv2-backend
8+
app.kubernetes.io/component: backend
9+
app.kubernetes.io/managed-by: kustomize
10+
spec:
11+
selector:
12+
app: nbv2-backend
13+
app.kubernetes.io/component: backend
14+
app.kubernetes.io/managed-by: kustomize
15+
ports:
16+
- port: 4000
17+
targetPort: 4000
18+
type: NodePort
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
labels:
5+
app: nbv2-backend
6+
app.kubernetes.io/component: backend
7+
app.kubernetes.io/managed-by: kustomize
8+
name: nbv2-backend
9+
namespace: backend-system

0 commit comments

Comments
 (0)