Skip to content

Commit

Permalink
doc(quickstarts): update Spring Boot example to 3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa authored Jan 15, 2025
1 parent c40d7da commit b82e86e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 104 deletions.
118 changes: 76 additions & 42 deletions quickstarts/maven/spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,108 @@ description: |
---
# Spring Boot Sample

This is a sample project to use Eclipse JKube plugins.
This is an example of a Spring Boot Web application demonstrating the use of Eclipse JKube Maven Plugin to deploy Spring Boot applications to Kubernetes and OpenShift.

**Notice:**
> k8s:watch / oc:watch goal won't work as Spring devtools automatically
> ignores projects named `spring-boot`, `spring-boot-devtools`, `spring-boot-autoconfigure`, `spring-boot-actuator`,
> `and spring-boot-starter`.
> [!NOTE]
> k8s:watch / oc:watch goal won't work as Spring devtools automatically ignores projects named `spring-boot`, `spring-boot-devtools`, `spring-boot-autoconfigure`, `spring-boot-actuator`, `and spring-boot-starter`.
>
> To learn how to use Spring Devtools with Eclipse JKube, please refer to the [`spring-boot-watch` quickstart](../spring-boot-watch/README.md).
### Steps to use
This example consists of a single `@RestController` that returns a simple greeting message.

Make sure that OpenShift/Kubernetes cluster or Minishift/Minikube is running. In case, if anything of this is not running, you can
run Minishift/Minikube to test this application by using following command.
It is built to showcase how to deploy Spring Boot applications, both native and JVM, to Kubernetes and OpenShift using Eclipse JKube.
Let's start by checking the JVM build mode.

## JVM build

To build the application in JVM mode, run the following command:

#### For OpenShift
```
minishift start
```
Below command will create your OpenShift resource descriptors.
```
mvn clean oc:resource -Popenshift
```bash
mvn clean package
```

Now start S2I build by hitting the build goal.
```
mvn package oc:build -Popenshift
This command will build the application and create a JAR file in the `target` directory.

To deploy the application to Kubernetes, run the following command:

> [!NOTE]
> In case it's a Minikube cluster you want to share the Docker registry first:
>
> `eval $(minikube docker-env)`
```bash
mvn -Pkubernetes k8s:build k8s:resource k8s:apply
```

Below command will deploy your application on OpenShift cluster.
Once the application is deployed and ready, the list of pods should display something like:

```bash
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
spring-boot-5987c95fd6-phwv4 1/1 Running 0 22s
```
mvn oc:deploy -Popenshift

You can now access your application using cURL with the following command:

```bash
$ curl $(minikube ip):$(kubectl get svc spring-boot -n default -o jsonpath='{.spec.ports[].nodePort}')
Greetings from Spring Boot!!
```

#### For Kubernetes
Start your cluster:
## Native Build

To build the application in JVM mode, run the following command:

```bash
mvn -Pnative clean native:compile
```
minikube start

This command will build the application and create a JAR file in the `target` directory.

To deploy the application to Kubernetes, run the following command:

> [!NOTE]
> In case it's a Minikube cluster you want to share the Docker registry first:
>
> `eval $(minikube docker-env)`
```bash
mvn -Pkubernetes k8s:build k8s:resource k8s:apply
```
Below command will create your Kubernetes resource descriptors.

Once the application is deployed and ready, the list of pods should display something like:

```bash
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
spring-boot-5987c95fd6-phwv4 1/1 Running 0 22s
```
mvn clean k8s:resource -Pkubernetes

You can now access your application using cURL with the following command:

```bash
$ curl $(minikube ip):$(kubectl get svc spring-boot -n default -o jsonpath='{.spec.ports[].nodePort}')
Greetings from Spring Boot!!
```

Now start docker build by hitting the build goal.
## For OpenShift

```
mvn package k8s:build -Pkubernetes
minishift start
```

Below command will deploy your application on Kubernetes cluster.
Below command will create your OpenShift resource descriptors.
```
mvn k8s:deploy -Pkubernetes
mvn clean oc:resource -Popenshift
```

Once deployed, you can see the pods running inside your Kubernetes cluster:
Now start S2I build by hitting the build goal.
```
~/work/repos/jkube/quickstarts/maven/spring-boot : $ kubectl get pods
NAME READY STATUS RESTARTS AGE
spring-boot-59b4bb66-j42fv 1/1 Running 0 94s
mvn package oc:build -Popenshift
```
You can try to access your application using `minikube service` command like this:

Below command will deploy your application on OpenShift cluster.
```
~/work/repos/jkube/quickstarts/maven/spring-boot : $ minikube service spring-boot
|-----------|-------------|-------------|----------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-------------|-------------|----------------------------|
| default | spring-boot | http | http://192.168.39.76:32429 |
|-----------|-------------|-------------|----------------------------|
Opening service default/spring-boot in default browser...
mvn oc:deploy -Popenshift
```

#### Generating Ingress for your generated Service
Expand Down
69 changes: 7 additions & 62 deletions quickstarts/maven/spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.17</version>
<version>3.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>org.eclipse.jkube.quickstarts.maven</groupId>
Expand All @@ -36,51 +37,31 @@
</description>

<properties>
<java.version>17</java.version>
<jkube.version>${project.version}</jkube.version>
</properties>

<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<dependencies>

<!-- Boot generator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.jolokia</groupId>
<artifactId>jolokia-core</artifactId>
</dependency>

</dependencies>

<build>
<plugins>

<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>


</plugins>
</build>

Expand All @@ -93,48 +74,29 @@
<groupId>org.eclipse.jkube</groupId>
<artifactId>kubernetes-maven-plugin</artifactId>
<version>${jkube.version}</version>

<configuration>

<resources>
<labels>
<all>
<testProject>spring-boot-sample</testProject>
</all>
</labels>
</resources>

<generator>
<includes>
<include>spring-boot</include>
</includes>
<config>
<spring-boot>
<color>always</color>
</spring-boot>
</config>
</generator>
<enricher>
<excludes>
<exclude>jkube-expose</exclude>
</excludes>
<config>
<jkube-service>
<type>NodePort</type>
</jkube-service>
</config>
</enricher>
</configuration>

<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
<goal>helm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -147,7 +109,6 @@
<groupId>org.eclipse.jkube</groupId>
<artifactId>openshift-maven-plugin</artifactId>
<version>${jkube.version}</version>

<configuration>
<resources>
<labels>
Expand All @@ -156,37 +117,21 @@
</all>
</labels>
</resources>

<generator>
<includes>
<include>spring-boot</include>
</includes>
<config>
<spring-boot>
<color>always</color>
</spring-boot>
</config>
</generator>
<enricher>
<excludes>
<exclude>jkube-expose</exclude>
</excludes>
<config>
<jkube-service>
<type>NodePort</type>
</jkube-service>
</config>
</enricher>
</configuration>

<executions>
<execution>
<goals>
<goal>resource</goal>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down

0 comments on commit b82e86e

Please sign in to comment.