2. Serverless Java on Kubernetes
Krzysztof Sobkowiak (@ksobkowiak)
https://blog.cdemi.io/what-is-serverless-architecture/
Wrocław, 01.03.2019
#TechTalkSE
3. About me
● Capgemini
○ Senior Delivery Architect, Trainer
○ JEE & OSS solutions, system integration, cloud, microservices,
devops
● Apache Software Foundation
○ Member
○ Apache ServiceMix Committer & PMC Chair (V.P. ServiceMix)
○ Contributor @ Apache Karaf, Apache CXF, Apache Camel,
Apache ActiveMQ
● Co-organizer of #geekweekwro
Views in this presentation are my personal views and do not necessarily reflect the views of Capgemini or The Apache Software Foundation.
10. What is serverless?
“Serverless computing refers to the concept of building and
running applications that do not require server management.
It describes a finer-grained deployment model where
applications, bundled as one or more functions, are uploaded
to a platform and then executed, scaled, and billed in
response to the exact demand needed at the moment.”
https://www.cncf.io/blog/2018/02/14/cncf-takes-first-step-towards-serverless-computing/
11. What is serverless?
“Serverless architectures are application designs that
incorporate third-party “Backend as a Service” (BaaS)
services, and/or that include custom code run in managed,
ephemeral containers on a “Functions as a Service” (FaaS)
platform.”
https://martinfowler.com/articles/serverless.html
12. Function as a Service (FaaS)
● Function
○ Small bits of code with a well defined job
○ Easy to understand and maintain
● As a service
○ The system takes care of provisioning, scaling, patching, …
○ Each function can scale independently
fx
28. ● Basic unit of work
● A stateless, relatively short-running function
● Invoked as an event handler.
● Invoking an action generates an "activation id",
used to retrieve results
Action
JSONJSON
30. Action - JavaScript
function main(params) {
return { payload: 'Hello ' + params.body.text +
' from JavaScript action on OpenWhisk on OpenShift '};
}
31. Creating an action
To create an action, we need to we need to give it a name and configure it in
OpenWhisk
$ wsk -i action create msgaction msgaction.js
32. Invoking an action
Once it has a name, it can be invoked directly:
$ wsk -i action invoke msgaction --param body '{"text":"Tech Talk SE"}' --result
{ "payload": "Hello Tech Talk SE from JavaScript action on OpenWhisk on OpenShift" }
$ wsk -i activation get -l # see the details, logs
33. Action - Python
def main(params):
return { "payload" :
"Hello " + str(params["body"]["text"]) +
" from Python action on OpenWhisk on OpenShift"}
34. Updating an action
$ wsk -i action update msgaction msgaction.py
$ wsk -i action invoke msgaction --param body '{"text":"Tech Talk SE"}' --result
{ "payload": "Hello Tech Talk SE from Python action on OpenWhisk on OpenShift" }
44. Serverless Microservices - web actions & api gateway
● Actions invoked via urls using HTTP
verbs like GET, POST, PUT, …
● Automatic content detection via
prefixing
● Api Gateway - proxy to Web Actions
○ HTTP method routing
○ client id/secrets
○ rate limiting
○ CORS
https://github.com/rabbah/wsk-qr
45. Web Actions & API Gateway
$ wsk -i action create fibonacci fibonacci.js --web true
$ WEB_URL=`wsk -i action get --url fibonacci | awk 'FNR==2{print $1}'`
$ curl -k $WEB_URL.json?num=5
$ wsk -i api create /fibonacci get fibonacci
$ curl -X GET ${API_URL}/api/${GENERATED_API_ID}/fibonacci?num=5
46. API Gateway
wsk api create -n "Book Club" /club /books/{isbn} get getBooks
wsk api create /club /books get getBooks
wsk api create /club /books post postBooks
wsk api create /club /books/{isbn} put putBooks
wsk api create /club /books/{isbn} delete deleteBooks
51. Event Driven Capabilities
● Triggers are channels for events
● Triggers can be linked, via rules, to one or more actions
● Events could be
○ Another function
○ External event source called as Feed Provider
● Trigger can be registered to Event Provider via Feeds (Stream of Events)
○ Feed can be:
■ Polling
■ Webhook
■ Persistent Connection JSON
57. Credits
Special thanks to all the people who made and released their awesome resources
for free:
● Serverless Java: Challenges and Triumphs by David Delabassee
● Serverless Java on Kubernetes by Burr Sutter and Rafael Benevides
● Functions as a Service with Apache OpenWhisk and Openshift by Brendan
McAdams
● Your Journey into the Serverless World by Kamesh Sampath