Second Assignment

This commit is contained in:
root 2026-04-29 00:16:48 +02:00
parent b9ec34979b
commit 5dda1586f9
11 changed files with 185 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.tar
uploads/

7
z1/Dockerfile.frontend Normal file
View File

@ -0,0 +1,7 @@
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY frontend/ /usr/share/nginx/html/
EXPOSE 80

7
z1/frontend/Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM nginx:alpine
RUN rm -rf /usr/share/nginx/html/*
COPY . /usr/share/nginx/html/
EXPOSE 80

6
z2/Dockerfile.backend Normal file
View File

@ -0,0 +1,6 @@
FROM node:18
WORKDIR /app
COPY backend/ .
RUN npm install
EXPOSE 3000
CMD ["node", "server.js"]

50
z2/k8s/deployment.yaml Normal file
View File

@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
namespace: z2
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: backend
image: z2_backend:latest
imagePullPolicy: Never
ports:
- containerPort: 3000
volumeMounts:
- name: uploads-volume
mountPath: /app/uploads
volumes:
- name: uploads-volume
emptyDir: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
namespace: z2
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: frontend
image: z2_frontend:latest
imagePullPolicy: Never
ports:
- containerPort: 80

4
z2/k8s/namespace.yaml Normal file
View File

@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: z2

26
z2/k8s/service.yaml Normal file
View File

@ -0,0 +1,26 @@
apiVersion: v1
kind: Service
metadata:
name: backend-service
namespace: z2
spec:
selector:
app: backend
ports:
- port: 3000
targetPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: frontend-service
namespace: z2
spec:
type: NodePort
selector:
app: frontend
ports:
- port: 80
targetPort: 80
nodePort: 30007

48
z2/k8s/statefulset.yaml Normal file
View File

@ -0,0 +1,48 @@
apiVersion: v1
kind: Service
metadata:
name: mongo
namespace: z2
labels:
app: mongo
spec:
clusterIP: None
selector:
app: mongo
ports:
- port: 27017
targetPort: 27017
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
namespace: z2
spec:
serviceName: mongo
replicas: 1
selector:
matchLabels:
app: mongo
template:
metadata:
labels:
app: mongo
spec:
containers:
- name: mongo
image: mongo:6
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-storage
spec:
accessModes:["ReadWriteOnce"]
resources:
requests:
storage: 1Gi

17
z2/prepare-app.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
echo "Preparing application..."
# FRONTEND
cd ../z1/frontend
docker build -t z2_frontend:latest .
docker save z2_frontend:latest -o frontend.tar
microk8s ctr image import frontend.tar
# BACKEND
cd ../backend
docker build -t z2_backend:latest .
docker save z2_backend:latest -o backend.tar
microk8s ctr image import backend.tar
echo "Preparation done!"

11
z2/start-app.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
echo "Starting Kubernetes application..."
microk8s kubectl apply -f k8s/namespace.yaml
microk8s kubectl apply -f k8s/statefulset.yaml
microk8s kubectl apply -f k8s/deployment.yaml
microk8s kubectl apply -f k8s/service.yaml
echo "Application started!"
echo "Open: http://147.232.204.210:30007"

7
z2/stop-app.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
echo "Stopping Kubernetes application..."
microk8s kubectl delete -f k8s/
echo "Application stopped!"