Skip to content

This project demonstrates deploying Spring Boot native applications as serverless functions on Kubernetes, leveraging Spring Boot native capabilities and Knative for efficiency, scalability, and resilience.

Notifications You must be signed in to change notification settings

rd4r3/spring-boot-knative-hello

Repository files navigation

Spring Boot Native Hello World on Knative

This project demonstrates deploying Spring Boot native applications as serverless functions on Kubernetes, leveraging Spring Boot native capabilities and Knative for efficiency, scalability, and resilience.

Table of Contents

  1. Compilation of HelloWorldSpringBoot to Native Executable
  2. Installation of Knative Using Quickstart
  3. Setup of Knative Cluster with setup-knative.sh

Compilation of HelloWorldSpringBoot to Native Executable

To compile the HelloWorldSpringBoot application to a native executable using Spring Native, follow these steps:

  1. Ensure you have GraalVM installed:

    sudo apt-get install graalvm-ce-java17
  2. Ensure you have the necessary dependencies in your pom.xml file:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
  3. Add the GraalVM native plugin to your pom.xml file:

    <plugin>
        <groupId>org.graalvm.buildtools</groupId>
        <artifactId>native-maven-plugin</artifactId>
        <version>0.11.2</version>
        <executions>
            <execution>
                <goals>
                    <goal>compile-no-fork</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <buildArgs>
                <!-- Optional: Add GraalVM native-image flags -->
                <buildArg>--no-fallback</buildArg>
                <buildArg>--enable-url-protocols=http,https</buildArg>
                <buildArg>--report-unsupported-elements-at-runtime</buildArg>
            </buildArgs>
        </configuration>
    </plugin>
  4. Build the native executable:

    mvn -Pnative native:compile
  5. Run the native executable:

    ./target/hello-world-spring-boot

Installation of Knative Using Quickstart

To install Knative using the quickstart method, follow the official Knative documentation:

Knative Quickstart Installation Guide

Setup of Knative Cluster with setup-knative.sh

To set up the Knative cluster using the setup-knative.sh script, follow these steps:

  1. Ensure you have the necessary permissions and tools installed:

    • kubectl
    • kind (Kubernetes IN Docker)
  2. Run the setup script:

    ./setup-knative.sh

This script will configure your Kubernetes cluster with Knative and deploy the necessary components.

Load Testing with wrk

To perform load testing on the deployed application, follow these steps:

  1. Install wrk:

    sudo apt-get install wrk
  2. Run the load test:

    wrk -t4 -c400 -d10s --latency -H "Host: hello-native-local.default.127.0.0.1.sslip.io" http://localhost:30641/hello

    This command runs a load test using wrk with the following parameters:

    • -t4: Use 4 threads.
    • -c400: Use 400 concurrent connections.
    • -d10s: Run the test for 10 seconds.
    • --latency: Display latency statistics.
    • -H "Host: hello-native-local.default.127.0.0.1.sslip.io": Set the Host header to simulate a request to the specified host.
    • http://localhost:30641/hello: The URL to test.
  3. Observe the number of pods:

    kubectl get pods -n default --no-headers | wc -l

    This command retrieves the number of pods running in the default namespace and counts them.

About

This project demonstrates deploying Spring Boot native applications as serverless functions on Kubernetes, leveraging Spring Boot native capabilities and Knative for efficiency, scalability, and resilience.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published