Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Knative and Spring: Bringing back the func

Knative and Spring: Bringing back the func

Kubernetes is now a standard to deploy and manage containerized applications. How do functions fit into the cloud-native space in 2022? What does it take to write a function in Java or any other language and get it up and running in a Kubernetes cluster?

We’ll show with practical examples and a live demo how developers can focus on the business logic while the platform takes care of supporting event-driven and serverless workloads in a polyglot environment.

- CloudEvents provide a language and transport-agnostic way to describe events.
- Knative Eventing routes CloudEvents between producers and consumers so that developers don’t have to worry about which message broker is used under the hood (e.g. RabbitMQ, Kafka, cloud-provider specific).
- Frameworks like Spring Cloud Functions let developers focus on implementing the business logic instead of dealing with infrastructural concerns and integrations with event brokers.
- GraalVM and libraries like Spring Native make it possible to build serverless applications in Java and take advantage of the scale-to-zero feature offered by Knative Serving.
- Cloud-Native Buildpacks solve the problem of building production-ready containers end to end, offering support for multiple languages and frameworks, and focusing on performance and security.

To demonstrate how all these tools can work together, we will show how Knative func combines them and provide developers with a Dockerfile-free and Kubernetes YAML-free experience.

Thomas Vitale

May 27, 2022
Tweet

More Decks by Thomas Vitale

Other Decks in Technology

Transcript

  1. Mauricio Salatino & Thomas Vitale
    Spring I/O
    May 27th, 2022
    Knative and Spring
    Bringing back the func
    @salaboy @vitalethomas

    View full-size slide

  2. Mauricio Salatino
    VMware - Knative OSS
    • a.k.a @Salaboy

    • Sta
    ff
    Engineer - Knative Eventing
    tech lead for VMware

    • Knative OSS core contributor

    • Passionate about Functions,
    Platforms, Open Source and
    Kubernetes

    salaboy.com

    View full-size slide

  3. Systematic
    • Software Architect at
    Systematic, Denmark.

    • Author of “Cloud Native Spring
    in Action” (Manning).

    • Spring Security and Spring
    Cloud contributor.
    Thomas Vitale
    thomasvitale.com @vitalethomas

    View full-size slide

  4. Quiz Game
    thomasvitale.com @vitalethomas
    @salaboy @vitalethomas
    Building applications using functions

    View full-size slide

  5. Serverless
    @salaboy @vitalethomas

    View full-size slide

  6. Serverless Architectures
    Developers focus on code
    Focus on business logic
    @salaboy @vitalethomas
    Developer
    Platform
    Infrastructure

    Provisioning
    Workload

    Management
    Dynamic

    Scaling

    View full-size slide

  7. Knative Serving
    Serverless Containers on Kubernetes
    Developer-friendly

    abstractions
    From code to URL
    Autoscaling

    Scaling to zero
    Progressive

    Rollouts
    Request-driven

    Event-driven
    @salaboy @vitalethomas
    Cloud agnostic

    View full-size slide

  8. buildpacks.io

    View full-size slide

  9. Demo
    thomasvitale.com @vitalethomas
    @salaboy @vitalethomas
    Knative Serving and Buildpacks - From code to URL

    View full-size slide

  10. Platform v1 - Serverless experience
    From containers to deployment with autoscaling
    @salaboy @vitalethomas
    Image
    pack kn
    URL
    Kubernetes Cluster
    Container
    Container
    Container
    Knative
    Serving

    View full-size slide

  11. Functions
    @salaboy @vitalethomas

    View full-size slide

  12. Demo
    thomasvitale.com @vitalethomas
    @salaboy @vitalethomas
    Knative Functions - From code to URL

    View full-size slide

  13. Functions
    Functional programming model
    Triggered by
    requests or events
    Stateless Smaller scope
    Cold start Cost optimization
    @salaboy @vitalethomas

    View full-size slide

  14. Functions Patterns
    Topologies for functional programming
    @salaboy @vitalethomas
    Asynchronous
    processing
    Event-based
    Data stream

    via chained
    functions
    Synchronous
    Asynchronous
    Fire and Forget
    Request/
    Response
    Request/
    Response (State)

    View full-size slide

  15. Knative Functions
    Working with the func CLI
    @salaboy @vitalethomas
    func create
    ‣Initialize project


    ‣Polyglot support


    ‣Java, Go, Python
    1
    func build
    ‣Build and containerize


    ‣Use Buildpacks


    ‣No Docker
    fi
    le
    2
    func deploy
    ‣Run on Kubernetes


    ‣Knative deployment


    ‣No YAML
    3

    View full-size slide

  16. More on Knative Functions
    In active development, join the community!
    External templates

    repository
    Run locally with

    func run
    On-cluster build,

    no Docker required
    Roadmap to 1.0 GA
    @salaboy @vitalethomas
    Works with multiple
    languages and
    frameworks

    View full-size slide

  17. Platform v2 - Polyglot Functions
    From idea to deployment with autoscaling
    @salaboy @vitalethomas
    URL
    func create
    Image
    func deploy
    Kubernetes Cluster
    Container
    Container
    Container
    Knative
    Serving

    View full-size slide

  18. Functions with Spring
    @salaboy @vitalethomas

    View full-size slide

  19. Spring Native
    Native executables with GraalVM
    Slower

    Heavier

    Build
    Instant

    Startup
    Reduced

    Memory

    Consumption
    Instant

    Peak

    Performance
    Fewer

    Runtime

    Optimizations
    @salaboy @vitalethomas

    View full-size slide

  20. Functional Programming Paradigm
    Java 8 Functional Interfaces
    Supplier Function Consumer
    @salaboy @vitalethomas

    View full-size slide

  21. Spring Cloud Function
    Business logic as functions
    Transparent

    Type

    Conversion
    Function

    Arity
    Function

    Composition
    Reactive

    Support
    JAR

    Functions
    @salaboy @vitalethomas

    View full-size slide

  22. Demo
    thomasvitale.com @vitalethomas
    @salaboy @vitalethomas
    Knative Functions - From code to URL

    View full-size slide

  23. Function Composition
    Data processing via functions
    uppercase() sentence()
    Data processing
    “I play the PIANO”
    “piano” “PIANO”

    View full-size slide

  24. Spring Cloud Function
    Deployment and integrations
    Knative CloudEvents RSocket
    Azure

    Functions
    Google Cloud
    Functions
    AWS

    Lambda
    @salaboy @vitalethomas

    View full-size slide

  25. Events
    @salaboy @vitalethomas

    View full-size slide

  26. CloudEvents
    Interoperability and standardization
    Metadata
    Data
    Id

    Source

    Type
    Payload
    JSON

    AMQP

    Kafka

    MQTT
    @salaboy @vitalethomas

    View full-size slide

  27. Spring Cloud Functions Routing
    Routing Events to functions
    A()
    CloudEvent
    B()
    C()
    Router


    [Ce-Type]

    View full-size slide

  28. Knative Eventing
    Event routing and triggers
    Developer-friendly

    abstractions
    Event-driven
    architectures
    Event routing
    Polyglot support
    with CloudEvents
    Pluggable
    @salaboy @vitalethomas
    Cloud agnostic

    View full-size slide

  29. Platform v3 - Knative Eventing
    Event-driven and reactive functions
    @salaboy @vitalethomas
    URL
    func create
    + trigger
    Image
    func deploy
    Kubernetes Cluster
    Container Container
    Knative
    Serving &
    Eventing
    Knative Broker
    Knative Event Sources
    Trigger A Trigger B

    View full-size slide

  30. Game - Architecture
    @salaboy @vitalethomas

    View full-size slide

  31. Kubernetes Cluster
    Game - Functions
    Synchronous functions with Knative



    React Application



    Game FrontEnd



    Start Game



    Level X






    Get LeaderB
    Redis


    (State)
    HTTP
    SYNC



    Level 1



    View full-size slide

  32. Takeaways and challenges
    Synchronous functions
    Functions scale up
    and down based on
    demand
    An Orchestrator is
    needed
    Synchronising state
    is hard
    Make sure that the
    data store is not a
    bottleneck
    Latency can
    become an issue
    @salaboy @vitalethomas

    View full-size slide

  33. Game - Eventing
    Knative Eventing, CloudEvents & RSocket
    Kubernetes Cluster



    React Application



    Game FrontEnd



    Level X



    Redis
    HTTP SYNC
    Broker
    Trigger
    Score

    CloudEvent
    RSocket
    GameScore

    CloudEvent
    Trigger
    Another
    Function

    View full-size slide

  34. Takeaways and challenges
    Eventing
    An event-based
    approach enable
    more reactive
    scenarios
    Knative Eventing
    abstracts the
    message broker
    implementations
    CloudEvents
    provide a standard
    structure for

    sharing data
    Monitoring is
    required to
    understand how
    data is
    fl
    owing
    We need to deal
    with eventual
    consistency in our
    applications
    @salaboy @vitalethomas

    View full-size slide

  35. Discount codes
    Manning
    • 45% discount code, valid for
    all products in all format

    • ctwspringio22


    • manning.com

    View full-size slide

  36. Resources
    Source code
    • Learn more about the game:

    • https://github.com/salaboy/from-monolith-to-k8s/tree/main/game

    • Deploy the game on Kubernetes:

    • https://github.com/ThomasVitale/eventing-game

    • Spring Cloud Function samples:

    • https://github.com/ThomasVitale/springio-2022-knative-spring-func

    View full-size slide