Skip to content
Open

Kube #30

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0977b7e
pushed
SwayamNac Apr 6, 2025
157c4f6
Update docker-compose.yml
Swayamnakshane Apr 7, 2025
df53f74
Update Dockerfile
Swayamnakshane Apr 7, 2025
3eb7751
Update bankapp-deployment.yml
Swayamnakshane Apr 12, 2025
43b6b2a
Delete kubernetes/bankapp-hpa.yml
Swayamnakshane Apr 12, 2025
a291f89
Delete kubernetes/bankapp-ingress.yml
Swayamnakshane Apr 12, 2025
6837bfe
Update bankapp-namespace.yaml
Swayamnakshane Apr 12, 2025
96ef1f2
Update bankapp-service.yaml
Swayamnakshane Apr 12, 2025
a71528a
Update configmap.yaml
Swayamnakshane Apr 12, 2025
e9d9390
Delete kubernetes/letsencrypt-clusterissuer.yaml
Swayamnakshane Apr 12, 2025
3ff137e
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
1574abe
Update mysql-service.yaml
Swayamnakshane Apr 12, 2025
7f3a681
Update persistent-volume-claim.yaml
Swayamnakshane Apr 12, 2025
c540fd6
Update persistent-volume.yaml
Swayamnakshane Apr 12, 2025
b5e8149
Update secrets.yaml
Swayamnakshane Apr 12, 2025
e6c9727
Update configmap.yaml
Swayamnakshane Apr 12, 2025
6e8aee2
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
86ad8bd
Update mysql-service.yaml
Swayamnakshane Apr 12, 2025
d0a31ff
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
502420f
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
02d37d5
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
dfdfd18
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
c56bbe9
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
ddcb169
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
15d0f21
Update secrets.yaml
Swayamnakshane Apr 12, 2025
37b6c4e
Update bankapp-deployment.yml
Swayamnakshane Apr 12, 2025
e0b3c45
Update persistent-volume.yaml
Swayamnakshane Apr 12, 2025
cb930ce
Update persistent-volume-claim.yaml
Swayamnakshane Apr 12, 2025
ccff992
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
d0b6471
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
64223fb
Update persistent-volume-claim.yaml
Swayamnakshane Apr 12, 2025
5f2c13e
Update persistent-volume-claim.yaml
Swayamnakshane Apr 12, 2025
7d724c0
Update persistent-volume.yaml
Swayamnakshane Apr 12, 2025
b02e0a8
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
1bc0ed5
Update mysql-deployment.yml
Swayamnakshane Apr 12, 2025
f3357df
Update docker-compose.yml
Swayamnakshane Apr 18, 2025
1b5fc72
Update bankapp-deployment.yml
Swayamnakshane Apr 18, 2025
f241fe1
kube added
SwayamNac Apr 26, 2025
79468f6
Delete kubernetes directory
Swayamnakshane Apr 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 11 additions & 36 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
#----------------------------------
# Stage 1
#----------------------------------

# Import docker image with maven installed
FROM maven:3.8.3-openjdk-17 as builder

# Add maintainer, so that new user will understand who had written this Dockerfile
MAINTAINER Madhup Pandey<madhuppandey2908@gmail.com>

# Add labels to the image to filter out if we have multiple application running
LABEL app=bankapp

# Set working directory
WORKDIR /src

# Copy source code from local to container
COPY . /src

# Build application and skip test cases
#---------------------------------stage1-----------------------------------------
FROM maven:3.9.6-eclipse-temurin-17-alpine AS builder
WORKDIR /app
COPY . .
RUN mvn clean install -DskipTests=true

#--------------------------------------
# Stage 2
#--------------------------------------

# Import small size java image
FROM openjdk:17-alpine as deployer

# Copy build from stage 1 (builder)
COPY --from=builder /src/target/*.jar /src/target/bankapp.jar

# Expose application port
EXPOSE 8080

# Start the application
ENTRYPOINT ["java", "-jar", "/src/target/bankapp.jar"]

#---------------------------------stage2-----------------------------------------
FROM openjdk:17-slim
WORKDIR /app
COPY --from=builder /app/target/*.jar /app/target/bank.jar
EXPOSE 8081
CMD ["java","-jar","/app/target/bank.jar"]
35 changes: 13 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,34 @@ services:
image: mysql:latest
container_name: mysql
environment:
- MYSQL_ROOT_PASSWORD=Test@123
- MYSQL_DATABASE=BankDB
MYSQL_ROOT_PASSWORD: Test@123
MYSQL_DATABASE: bankappdb
ports:
- "3306:3306"
volumes:
- bankapp-volume:/var/lib/mysql
networks:
- bankapp
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3
start_period: 30s


mainapp:
image: ${DUSER}/${IMAGE}
container_name: Bankapp
image: bankapp:latest
container_name: "Bankapp"
environment:
- SPRING_DATASOURCE_USERNAME=root
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/BankDB?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
- SPRING_DATASOURCE_PASSWORD=Test@123
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bankappdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
SPRING_DATASOURCE_PASSWORD: Test@123
ports:
- "8080:8080"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Port mismatch: container expects 8081
The Kubernetes manifest and Dockerfile expose port 8081, but this service maps 8080:8080. This inconsistency will break connectivity. Update to:

-      - "8080:8080"
+      - "8081:8081"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- "8080:8080"
- "8081:8081"

depends_on:
mysql:
condition: service_healthy
- mysql
networks:
- bankapp
restart: always
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:8080/actuator/health || exit 1"]
interval: 10s
timeout: 5s
retries: 5
start_period: 30s


networks:
bankapp:

volumes:
bankapp-volume:
bankapp-volume:
4 changes: 4 additions & 0 deletions kube/Namespace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Namespace
apiVersion: v1
metadata:
name: bank
38 changes: 38 additions & 0 deletions kube/bank-deployement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: bank-deployment
namespace: bank
labels:
Comment on lines +3 to +6
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

File naming and metadata consistency
The filename bank-deployement.yml is misspelled (“deployement” vs. “deployment”). Rename it to bank-deployment.yml to align with Kubernetes conventions and avoid confusion or CI/apply errors.

app: app
spec:
replicas: 3
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
containers:
- name: bank-cont
image: swayamnakshane/mybank:latest
ports:
- containerPort: 8081
env:
Comment on lines +19 to +23
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Explicitly set imagePullPolicy and resource constraints
Relying on :latest without a pull policy may skip new image pulls. Also, adding resource requests/limits improves scheduler decisions and stability.

Apply this diff:

 spec:
   containers:
   - name: bank-cont
     image: swayamnakshane/mybank:latest
+    imagePullPolicy: Always
+    resources:
+      requests:
+        cpu: "100m"
+        memory: "256Mi"
+      limits:
+        cpu: "500m"
+        memory: "512Mi"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: bank-cont
image: swayamnakshane/mybank:latest
ports:
- containerPort: 8081
env:
- name: bank-cont
image: swayamnakshane/mybank:latest
imagePullPolicy: Always
resources:
requests:
cpu: "100m"
memory: "256Mi"
limits:
cpu: "500m"
memory: "512Mi"
ports:
- containerPort: 8081
env:

- name: SPRING_DATASOURCE_USERNAME
valueFrom:
configMapKeyRef:
name: bank-configmap
key: SPRING_DATASOURCE_USERNAME
- name: SPRING_DATASOURCE_URL
valueFrom:
configMapKeyRef:
name: bank-configmap
key: SPRING_DATASOURCE_URL
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: bank-secret
key: SPRING_DATASOURCE_PASSWORD
16 changes: 16 additions & 0 deletions kube/bank-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
kind: Service
apiVersion: v1
metadata:
name: bank-svc
namespace: bank
labels:
app: app
spec:
type: NodePort
selector:
app: app
ports:
- protocol: TCP
targetPort: 8080
port: 8081
nodePort: 30080
Comment on lines +13 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify container port mapping consistency.
The Service’s targetPort is set to 8080 while the application Deployment manifest (in kube/bank-deployement.yml) is said to expose port 8081. If the pod truly listens on 8081, traffic won’t reach it. Please confirm the container’s port or update targetPort to match.


🏁 Script executed:

#!/bin/bash
set -e
# Locate the Deployment manifest(s) for the bank service and check container ports
rg -n "containerPort" -g "kube/bank*.yml"

Length of output: 111


Update Service targetPort to match Deployment’s containerPort

The Deployment in kube/bank-deployement.yml exposes port 8081, but the Service’s targetPort is still set to 8080. This mismatch will prevent traffic from reaching the pods.

• kube/bank-deployement.yml (line 22):

  • containerPort: 8081
    • kube/bank-service.yml (lines 13–16):
  • targetPort: 8080

Suggested change:

--- a/kube/bank-service.yml
+++ a/kube/bank-service.yml
@@ -13,3 +13,3 @@
-      targetPort: 8080
+      targetPort: 8081
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- protocol: TCP
targetPort: 8080
port: 8081
nodePort: 30080
- protocol: TCP
targetPort: 8081
port: 8081
nodePort: 30080

10 changes: 10 additions & 0 deletions kube/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:v1.31.2
- role: worker
image: kindest/node:v1.31.2
- role: worker
image: kindest/node:v1.31.2

9 changes: 9 additions & 0 deletions kube/configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: bank-configmap
namespace: bank
data:
MYSQL_DATABASE: bankappdb
SPRING_DATASOURCE_USERNAME: root
SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/bankappdb?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC
50 changes: 50 additions & 0 deletions kube/mysql-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mysql-deployment
namespace: bank
labels:
app: bankapp
spec:
serviceName: mysql
replicas: 2
selector:
matchLabels:
app: bankapp
template:
metadata:
labels:
app: bankapp
spec:
containers:
- name: mysql
image: mysql:latest
ports:
- containerPort: 3306
Comment on lines +20 to +23
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid using the latest image tag.
Pin the MySQL container to a specific version (for example, mysql:8.0.33) to guarantee reproducible deployments and prevent unexpected upgrades.

env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: bank-secret
key: MYSQL_ROOT_PASSWORD
- name: MYSQL_DATABASE
valueFrom:
configMapKeyRef:
name: bank-configmap
key: MYSQL_DATABASE
volumeMounts:
- name: mysql
mountPath: /var/lib/mysql

volumeClaimTemplates:
- metadata:
name: mysql
labels:
app: bankapp
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

17 changes: 17 additions & 0 deletions kube/mysql-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: bank
labels:
app: bankapp

spec:
clusterIP: None
selector:
app: bankapp
ports:
- protocol: TCP
port: 3306
targetPort: 3306

16 changes: 16 additions & 0 deletions kube/persistentvolume.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: mysql-pv
namespace: bank
labels:
app: bankapp
Comment on lines +4 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove namespace from PersistentVolume
PersistentVolume is a cluster-scoped resource and does not support a namespace field; this should be removed to avoid API errors.

Apply this diff:

 metadata:
   name: mysql-pv
-  namespace: bank
   labels:
     app: bankapp

spec:
storageClassName: standard
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data/mysql"

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
namespace: bankapp-namespace
namespace: bank
labels:
app: bankapp
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
storageClassName: standard
storage: 5Gi

9 changes: 9 additions & 0 deletions kube/secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: bank-secret
namespace: bank
type: opaque
data:
MYSQL_ROOT_PASSWORD: VGVzdEAxMjM=
SPRING_DATASOURCE_PASSWORD: VGVzdEAxMjM=
Loading