From e850043632c491eade5fa3aff9764ff3b96a6f8a Mon Sep 17 00:00:00 2001 From: Yasindu20 Date: Fri, 10 Oct 2025 09:51:26 +0530 Subject: [PATCH 1/4] mongodb connect with env --- .gitignore | 3 +++ k8s/mongodb.yaml | 28 +++++++++++++++++----------- k8s/namespace.yaml | 15 ++------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index ad7360d..a906d66 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ override.tf.json # OS-specific .DS_Store Thumbs.db + +# Kubernetes Secret +k8s/mongodb-secret.yaml \ No newline at end of file diff --git a/k8s/mongodb.yaml b/k8s/mongodb.yaml index 5be604c..6696b46 100644 --- a/k8s/mongodb.yaml +++ b/k8s/mongodb.yaml @@ -1,9 +1,9 @@ -apiVersion : app/v1 +apiVersion : apps/v1 kind: StatefulSet metadata: name: mongodb namespace: issue-tracker -specs: +spec: serviceName: "mongodb" replicas: 1 selector: @@ -11,19 +11,25 @@ specs: app: mongodb template: metadata: - Labels: + labels: app: mongodb - specs: + spec: containers: - name: mongodb image: mongo:6-jammy ports: - - container-ports: 27017 + - containerPort: 27017 env: - name: MONGO_INITDB_ROOT_USERNAME - value: Yasindu + valueFrom: + secretKeyRef: + name: app-secret + key: mongo-user - name: MONGO_INITDB_ROOT_PASSWORD - value: yasindu20 + valueFrom: + secretKeyRef: + name: app-secret + key: mongo-password volumeMounts: - name: mongodb-storage mountPath: /data/db @@ -40,7 +46,7 @@ specs: - mongosh - --eval - db.adminCommand('ping') - intialDelaySeconds: 30 + initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: exec: @@ -48,7 +54,7 @@ specs: - mongosh - --eval - db.adminCommand('ping') - intialDelaySeconds: 5 + initialDelaySeconds: 5 periodSeconds: 5 volumeClaimTemplates: - metadata: @@ -61,7 +67,7 @@ specs: --- apiVersion: v1 -kind: service +kind: Service metadata: name: mongodb namespace: issue-tracker @@ -70,5 +76,5 @@ spec: app: mongodb ports: - port: 27017 - targetport: 27017 + targetPort: 27017 clusterIP: None \ No newline at end of file diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml index 530da91..3b41ce5 100644 --- a/k8s/namespace.yaml +++ b/k8s/namespace.yaml @@ -1,10 +1,10 @@ apiVersion: v1 -kind: namespace +kind: Namespace metadata: name: issue-tracker labels: name: issue-tracker - + --- apiVersion: v1 kind: ConfigMap @@ -14,14 +14,3 @@ metadata: data: NODE_ENV: "production" REACT_APP_API_URL: "http://localhost:8080/api" - ---- -apiVersion: v1 -kind: secret -metadata: - name: app-secret - namespace: issue-tracker -type: Opaque -stringData: - mongodb-uri: "mongodb+srv://Yasindu:yasindu20@issue-tracker-free.ffoquxf.mongodb.net/?retryWrites=true&w=majority&appName=issue-tracker-free" - jwt-secret: "your-super-secret-jwt-key-here-make-it-long-and-complex" From 325e0492e04c557a8d323b5f93ecd5161df062e4 Mon Sep 17 00:00:00 2001 From: Yasindu20 Date: Sun, 12 Oct 2025 16:08:29 +0530 Subject: [PATCH 2/4] backend k8s --- k8s/backend.yaml | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 k8s/backend.yaml diff --git a/k8s/backend.yaml b/k8s/backend.yaml new file mode 100644 index 0000000..6ea49e7 --- /dev/null +++ b/k8s/backend.yaml @@ -0,0 +1,112 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backend + namespace: issue-tracker + labels: + app: backend +spec: + replicas: 2 + selector: + matchLabels: + app: backend + templete: + metadata: + labels: + app: backend + spec: + containers: + - name: backend + image: yasindudemel/issue-tracker-backend:latest + ports: + -containerPorts: 8080 + env: + - name: NODE_ENV + valueFrom: + configMapKeyRef: + name: app-Config + key: NODE_ENV + - name: REACT_APP_API_URL + valueFrom: + configMapKeyRef: + name: app-Config + key: REACT_APP_API_URL + - name: JWT_SECRET + valueFrom: + secretKeyRef: + name: app-secret + key: jwt-secret + - name: MONGO_URI + value: "mongodb://$(MONGO_USER):$(MONGO_PASSWORD)@mongodb:27017/issue-tracker?authSource=admin" + - name: MONGO_USER + valueFrom: + secretKeyRef: + name: app-secret + key: mongo-user + - name: MONGO_PASSWORD + valueFrom: + secretKeyRef: + name: app-secret + key: mongo-password + resources: + requests: + memory: "256Mi" + cpu: "250m" + limits: + memory: "512Mi" + cpu: "500m" + livenessProbe: + httpGet: + path: /api/health + port: 5000 + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + httpGet: + path: /api/health + port: 5000 + initialDelaySeconds: 5 + periodSeconds: 5 +--- +apiVersion: v1 +kind: Service +metadata: + name: backend-service + namespace: issue-tracker +spec: + selector: + app: backend + ports: + - port: 8080 + targetPort: 8080 + protocol: TCP + type: ClusterIP + + --- + apiVersion: autoscaling/v2 + kind: HorizontalPodAutoscaler + metadata: + name: backend-hpa + namespace: issue-tracker + spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: backend + minReplicas: 1 + maxReplicas: 5 + matrics: + - type: Resource + resource: + name: cpu + target: + type: utilization + avarageUtilization: 70 + - type: Resource + resource: + name: memory + target: + type: utilization + avarageUtilization: 80 + + \ No newline at end of file From abd2bf8d5109337a696a48a536dbe3c40a62cf9e Mon Sep 17 00:00:00 2001 From: Yasindu20 Date: Sun, 12 Oct 2025 23:40:44 +0530 Subject: [PATCH 3/4] frontend k8s --- k8s/frontend.yaml | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 k8s/frontend.yaml diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml new file mode 100644 index 0000000..937d597 --- /dev/null +++ b/k8s/frontend.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: frontend + namespace: issue-tracker + labels: + app: frontend +spec: + replicas: 2 + selector: + matchLables: + app: frontend + templete: + metadata: + lables: + app: frontend + spec: + containers: + - name: frontend + image: yasindudemel/issue-tracker-frontend:latest + ports: + - containerPort: 80 + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "100m" + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 30 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 5 +--- +apiVersion: v1 +kind: Service +metadata: + name: frontend-service + namespace: issue-tracker + labels: + app: frontend +spec: + selector: + app: frontend + ports: + - port: 80 + targetPort: 80 + protocol: TCP + type: ClusterIP From 8d9696a2b39928526fac15a1200567b6bdcdd469 Mon Sep 17 00:00:00 2001 From: Yasindu20 Date: Mon, 13 Oct 2025 08:47:58 +0530 Subject: [PATCH 4/4] ingress.kubernetes.io --- k8s/frontend.yaml | 27 +++++++++++++++++++++++++++ k8s/ingress.yaml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 k8s/ingress.yaml diff --git a/k8s/frontend.yaml b/k8s/frontend.yaml index 937d597..52797e1 100644 --- a/k8s/frontend.yaml +++ b/k8s/frontend.yaml @@ -55,3 +55,30 @@ spec: targetPort: 80 protocol: TCP type: ClusterIP + +--- +apiVersion: autoscaling/v2 +kinf: HorizontalPodAutoscaler +metadata: + name: frontend-hpa + namespace: issue-tracker +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: frontend + minReplicas: 1 + maxReplicas: 5 + metrics: + - type: Resource + resource: + name: cpu + target: + type: utilization + avarageUtilization: 70 + - type: Resource + resource: + name: memory + target: + type: utilization + avarageUtilization: 80 diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..212ff9c --- /dev/null +++ b/k8s/ingress.yaml @@ -0,0 +1,35 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: issue-tracker-Ingress + namespace: issue-tracker + anootations: + nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/ssl-redirect: "true" + nginx.ingress.kubernetes.io/force-ssl-redirect: "true" + cert-manager.io/cluster-issuer: "letsencrpyt-prod" +spec: + ingressClassName: nginx + tls: + - hosts: + - issue-tracker.issueTracker.com + secretName: issue-tracker-tls + rules: + - hosts: + - issue-tracker.issueTracker.com + http: + paths: + path: / + pathType: prefix + backend: + service: + name: frontend-service + port: + number: 80 + path: /api + pathType: Prefix + backend: + service: + name: backend-service + port: + number: 5000 \ No newline at end of file