Il talk, basato su esempi pratici, esplora le caratteristiche di una piattaforma serverless Open Source (fnproject.io) associando l'attività di sviluppo software a tre temi fondamentali: la capacità di utilizzare contemporaneamente linguaggi e run-time differenti (Poliglottismo), la possibilità di usare - e riusare - un meccanismo di packaging elegante e diffuso (Docker), l'integrazione con Kubernetes e la flessibilità di utilizzo nel Cloud, on-premise o sul proprio laptop (Ubiquità).
2. What is Serverless?
● Serverless is an abstraction of infrastructure and its operations
including provisioning, scaling, patching, etc.
● Serverless architecture is when an app is built entirely on
serverless components (compute, storage, networking)
● Faas is the compute component in a serverless architecture
3. Functions-as-a-Service
● Functions are small bits of code that do one thing well and are
easy to understand and maintain
● As a service means no complicated plumbing, the system
takes care of provisioning, scaling, patching, maintaining, etc.
Each function scales independently.
In mathematics, a function is a relation between a set
of inputs and a set of permissible outputs with the
property that each input is related to exactly one output.
Function (mathematics) - Wikipedia
https://en.wikipedia.org/wiki/Function_(mathematics)
4. Containers vs Functions
Function is a container with a
set of known traits:
● Short running
● Ephemeral
● Stateless
● Invoked
● Single Purpose
● Self-contained
6. Introducing the Fn Project
● Launched in October focused on open source (apache 2),
multi-cloud, serverless services, starting with FaaS
● Iron.io team joined Oracle, now a 20-person “serverless” org
● Maniacal focus on the developer experience
● Independently governed at github.com/fnproject (currently)
● Members on the CNCF serverless working group
● We are building our community and partnerships
8. An Fn Function
● Small chunk of code wrapped into a container image
● Gets input via STDIN and environment
● Produces output to STDOUT
● Logs to STDERR
The Fn server handles everything else, like the API gateway,
piping things around, storing logs, etc.
9. Fn CLI
● fn init --runtime go
● fn run
● fn test
● fn deploy --app myapp
● fn call myapp myfunc
→ http://localhost:8080/r/myapp/myfunc
10. Function Development Kits (FDKs)
● Used to help with parsing input and writing output
● Familiar syntax for Lambda developers
● Simply write a `handler` function that adheres to the FDK’s
interface and it will parse STDIN and provide the input data to
your function and deal with writing the proper output format.
● Makes it a lot easier to write hot functions
11. Debugging
● fn calls list myapp
● fn calls get myapp <call-id>
● fn logs get myapp <call-id>
● Metrics created using OpenTracing w/ initial collectors and
extensions for Prometheus, ZipKin, and soon Jaeger
16. Fn Server
● Handles CRUD operations for setting up routes and functions
● Executes sync functions, returning responses to clients
immediately
● Queues async function calls
● Executes async functions when capacity is available
● Written in Go, easy to extend via plugin module system
17. Fn LB
● Simple, fast load balancer that routes functions to certain
nodes consistently for hot function efficiency
● Scales each function independently based on traffic to any
particular function
● Can be used to scale Fn servers and infrastructure as well as it
has a view of global state of all fn servers
19. Supporting Services
● DB, MQ, blob store are all pluggable modules that are thin
wrappers around their respective drivers.
○ DB: MySQL, sqlite3, Postgres
○ Queue: Redis, Kafka
○ Registry: Any Docker v2-compliant, even private
● Metrics/Monitoring
○ OpenTracing API for metrics
○ Prometheus support, pluggable backends
○ Logging via syslog
20. Kubernetes
● Fn is scheduler agnostic but lots of optimization/management
work in process to optimize on Kubernetes
● Helm chart available at https://github.com/fnproject/fn-helm
● Thinking about deeper Kubernetes integrations including
CRD’s to model functions
21. Helm Chart for K8S
IaaS
Environment
K8S
Cluster
Fn Instance
within K8S
terraform init
terraform plan
terraform apply
helm init
helm dep build fn
helm install --name
myfn fn
export FN_API_URL=<K8S LB url>
fn deploy --name myapp /comuni
fn apps list
fn routes list myapp
24. Fn Flow
● Build long-running, reliable, scalable functions with rich sets of
language-specific primitives including fork-join, chaining, delays
and error handling
● Supports complex parallel processes that are readable and
testable (including unit tests) with standard programming tools
● Java support using CompletableFuture API from Java 8 with
JS, Python, Go language support on the way!