From 9ece8e6098a83fc7600e9590a0a0651ed35ef7a0 Mon Sep 17 00:00:00 2001 From: Benjamin Loh Date: Mon, 30 Oct 2023 11:38:35 +0800 Subject: [PATCH] k8s yaml files k8s yaml files --- safeshare/K8s/backend_deployment.yaml | 68 ++++++++++++++++ safeshare/K8s/backend_service.yaml | 13 +++ safeshare/K8s/frontend_deployment.yaml | 25 ++++++ safeshare/K8s/frontend_service.yaml | 15 ++++ safeshare/K8s/redis_deployment.yaml | 106 +++++++++++++++++++++++++ 5 files changed, 227 insertions(+) create mode 100644 safeshare/K8s/backend_deployment.yaml create mode 100644 safeshare/K8s/backend_service.yaml create mode 100644 safeshare/K8s/frontend_deployment.yaml create mode 100644 safeshare/K8s/frontend_service.yaml create mode 100644 safeshare/K8s/redis_deployment.yaml diff --git a/safeshare/K8s/backend_deployment.yaml b/safeshare/K8s/backend_deployment.yaml new file mode 100644 index 0000000..ab1fa4d --- /dev/null +++ b/safeshare/K8s/backend_deployment.yaml @@ -0,0 +1,68 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: safeshare-backend + labels: + app: safeshare +spec: + replicas: 3 + selector: + matchLabels: + app: safeshare + tier: backend + template: + metadata: + labels: + app: safeshare + tier: backend + spec: + containers: + - name: safeshare-backend + image: amusement3004/safeshare + imagePullPolicy: IfNotPresent + env: + - name: DEBUG + value: "True" + - name: SECRET_KEY + value: A_RANDOM_SECRET_KEY + - name: ALLOWED_HOSTS + value: "*" + - name: CACHE + value: "True" + - name: REDIS_HOST + value: redis # Use the DNS name of the Redis service within the cluster + - name: REDIS_PORT + value: "6379" + - name: REDIS_DB + value: "0" + ports: + - containerPort: 8000 + volumeMounts: + - name: safeshare-persistent-storage + mountPath: /var/lib/safeshare + volumes: + - name: safeshare-persistent-storage + persistentVolumeClaim: + claimName: redis-pv-claim + +--- +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: safeshare-backend-hpa + labels: + app: safeshare +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: safeshare-backend + minReplicas: 3 + maxReplicas: 6 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 \ No newline at end of file diff --git a/safeshare/K8s/backend_service.yaml b/safeshare/K8s/backend_service.yaml new file mode 100644 index 0000000..dff7908 --- /dev/null +++ b/safeshare/K8s/backend_service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: safeshare-backend-service +spec: + selector: + app: safeshare + tier: backend + ports: + - protocol: TCP + port: 80 + targetPort: 8000 + type: LoadBalancer \ No newline at end of file diff --git a/safeshare/K8s/frontend_deployment.yaml b/safeshare/K8s/frontend_deployment.yaml new file mode 100644 index 0000000..23061af --- /dev/null +++ b/safeshare/K8s/frontend_deployment.yaml @@ -0,0 +1,25 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: safeshare-frontend + labels: + app: safeshare + tier: frontend +spec: + replicas: 1 # Since you mentioned you didn't want replicas for frontend + selector: + matchLabels: + app: safeshare + tier: frontend + template: + metadata: + labels: + app: safeshare + tier: frontend + spec: + containers: + - name: safeshare-frontend + image: amusement3004/safeshare-frontend:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 80 # Assuming your React app runs on port 80 \ No newline at end of file diff --git a/safeshare/K8s/frontend_service.yaml b/safeshare/K8s/frontend_service.yaml new file mode 100644 index 0000000..5f5eb24 --- /dev/null +++ b/safeshare/K8s/frontend_service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: safeshare-frontend-service + labels: + app: safeshare + tier: frontend +spec: + type: LoadBalancer # This will expose the service externally, adapt based on your cloud provider or environment + ports: + - port: 80 # Matching the container port + targetPort: 80 + selector: + app: safeshare + tier: frontend \ No newline at end of file diff --git a/safeshare/K8s/redis_deployment.yaml b/safeshare/K8s/redis_deployment.yaml new file mode 100644 index 0000000..d9fc105 --- /dev/null +++ b/safeshare/K8s/redis_deployment.yaml @@ -0,0 +1,106 @@ +apiVersion: v1 +kind: Service +metadata: + name: redis + labels: + app: safeshare +spec: + ports: + - port: 6379 + selector: + app: safeshare + tier: redis + clusterIP: None + +--- + +kind: PersistentVolume +apiVersion: v1 +metadata: + name: redis-pv-volume + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 2Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/data" + +--- + +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: redis-pv-claim + labels: + app: safeshare +spec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 2Gi + +--- + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: safeshare-redis + labels: + app: safeshare +spec: + replicas: 3 + selector: + matchLabels: + app: safeshare + tier: redis + strategy: + type: Recreate + template: + metadata: + labels: + app: safeshare + tier: redis + spec: + containers: + - image: redis:latest + name: redis + command: ["redis-server"] + ports: + - containerPort: 6379 + name: redis + volumeMounts: + - name: redis-persistent-storage + mountPath: /var/lib/redis + volumes: + - name: redis-persistent-storage + persistentVolumeClaim: + claimName: redis-pv-claim + +--- + +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: safeshare-redis-hpa + labels: + app: safeshare +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: safeshare-redis + minReplicas: 3 + maxReplicas: 6 + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 \ No newline at end of file