This commit is contained in:
Rajesh1b 2024-09-26 12:10:05 +00:00 committed by GitHub
commit 27ead41283
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 0 deletions

34
Dockerfile Normal file
View file

@ -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"]

21
k8s/deployment.yaml Normal file
View file

@ -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

17
k8s/service.yaml Normal file
View file

@ -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