Spring Pet Clinic¶
The Spring Pet Clinic is a sample Java application built with Spring Boot. It demonstrates a typical multi-tier web application with a web UI, REST API, and database backend.
Deploy with Source-to-Image (S2I)¶
-
Create a namespace:
-
Deploy the application using S2I:
oc new-app --image-stream="openshift/java:openjdk-21-ubi8" \ https://github.com/spring-projects/spring-petclinic.git \ --name=petclinicThis builds the application from source using the OpenShift Java builder image.
-
Watch the build progress:
-
Expose the application with a Route:
-
Verify the deployment:
Deploy from Container Image¶
Alternatively, deploy a pre-built image:
-
Create a namespace:
-
Create the Deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: petclinic namespace: petclinic labels: app: petclinic spec: replicas: 1 selector: matchLabels: app: petclinic template: metadata: labels: app: petclinic spec: containers: - name: petclinic image: docker.io/springcommunity/spring-petclinic:latest ports: - containerPort: 8080 resources: requests: memory: "512Mi" cpu: "250m" limits: memory: "1Gi" cpu: "500m" readinessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 30 periodSeconds: 10 livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 60 periodSeconds: 10 -
Create a Service and Route:
-
Verify it's running:
oc get pods -n petclinic ROUTE=$(oc get route petclinic -o jsonpath='{.spec.host}') curl -s -o /dev/null -w "%{http_code}" http://$ROUTEYou should see HTTP status
200once the application has started.
Deploy with a PostgreSQL Database¶
By default, Pet Clinic uses an in-memory H2 database. For a persistent setup, deploy with PostgreSQL:
-
Deploy PostgreSQL:
-
Deploy Pet Clinic with the PostgreSQL profile:
-
Expose and verify: