diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e98b32df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# setting the base image, will be creating the build image +FROM maven:3.8.8-eclipse-temurin-17 AS builder + +# setting up the work directory +WORKDIR /app + +# Copy the project files +COPY pom.xml . + +# run the mvn dependencies +RUN mvn dependency:go-offline + +# copy all the data to work directory +COPY . . + +# running mvn clean at build time +RUN mvn clean package -DskipTests + +# Use a lightweight JDK runtime for the final image +# using multiple from to build multi-stage image +FROM openjdk:17-jdk-slim + +# setting the new work directory +WORKDIR /app + +# Copy the built JAR from the builder stage +COPY --from=builder /app/target/*.jar app.jar + +# exposing port 8080 where java app will run +EXPOSE 8080 + +# setting the entry point, to run the application when it comes live +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 00000000..7f701105 --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-world-deployment + labels: + app: java-application +spec: + replicas: 3 + selector: + matchLabels: + app: java-application + template: + metadata: + labels: + app: java-application + spec: + containers: + - name: java-application + image: abhiramikannan/javaimage:latest + ports: + - containerPort: 8080 diff --git a/service.yaml b/service.yaml new file mode 100644 index 00000000..7b1ce6ee --- /dev/null +++ b/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-service +spec: + type: NodePort + selector: + app: java-application + ports: + - port: 8080 + # By default and for convenience, the `targetPort` is set to + # the same value as the `port` field. + targetPort: 8080 + # Optional field + # By default and for convenience, the Kubernetes control plane + # will allocate a port from a range (default: 30000-32767) + nodePort: 30007