diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..fa9075747 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +#stage 1 +# Use a base image with OpenJDK +FROM openjdk:17-jdk-slim as build + +# Set the working directory +WORKDIR /app + +# Install Maven +RUN apt-get update && \ + apt-get install -y maven && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy the project files into the container +COPY . . + +# Package the application using Maven +RUN ./mvnw package + +#stage 2 +# Stage 2: Create a Distroless image +FROM gcr.io/distroless/java17 + +# Set the working directory +WORKDIR /app + +# Copy the packaged JAR from the build stage +COPY --from=build /app/target/spring-petclinic-3.3.0-SNAPSHOT.jar app.jar + +#Expose port +EXPOSE 8080 + +#cmd command +CMD ["app.jar"] diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 000000000..4dc2304b1 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: petclinic + labels: + app: petclinic +spec: + replicas: 3 + selector: + matchLabels: + app: petclinic + template: + metadata: + labels: + app: petclinic + spec: + containers: + - name: petclinic-container + image: nginx:1.14.2 + ports: + - containerPort: 80 diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 000000000..00e5e077e --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: petclinic-service +spec: + type: NodePort + selector: + app: petclinic + ports: + - port: 80 + # 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