Cloud Native Akka & Kubernetes: the holy grail to elasticity? by Fabio Tiriticco
Have you ever wondered how to actually achieve elasticity on the cloud, outside of your cushy local dev environment?
Akka is the most mature choice to implement the traits of the Reactive Manifesto, thanks to the Actor model. Resilience is enabled by asynchronous message passing and Actor supervision. Location transparency, message routing and the “share nothing” approach enable seamless scalability, but once our app is deployed we need to rely on some external infrastructure to automatically scale up or down our services. At this point, Akka alone is not sufficient anymore. What else do we need?
We found Docker & Kubernetes to be a perfect match for clustered Akka applications running in the cloud. Thanks to the Kubernetes API, one can write infrastructure logic that complements the business logic. This leads to a general approach of infrastructure-as-code tailored to each different business case, which in turn lets companies achieve maximum efficiency and resource usage.
During this talk we will cover features from both Akka and Kubernetes, plus example code in Scala: familiarity with these technologies is recommended. Our example will rely on Google Cloud infrastructure.
5. Akka’s building blocks: Actors
• contains state &
behaviour logic
Actor 1
Actor 3
Actor 2
• has an addressable
mailbox to receive
and send messages
myActor3.getName()
“Joe”
“What is your name?”
“My name is Joe”
“Bob”
“Tim”
8. My first journey in the Reactive world
Phone 1
actor
Phone 2
actor
Matcher
actor
Phone 3
actor
A possible architecture
for CloudMatch
Phone 4
actor
“You matched with Phone
4, his address is xxx”
“You matched
with Phone 1,
his address is
yyy”
14. Issue #1: how to distribute this?
Job
source
Master
Worker
Worker
Scaling
controller
15. Node 1
Akka Cluster to the rescue!
• Joining
• Up
• Leaving
• Unreacheable
• …
Seed
Node 1
Seed
Node 2
Node 2
Node 3
NOTE: nodes need to know where the seed is
16. Moving workers to different nodes
JVM 2 - worker
JVM 3 - worker
Job
source
Master
Worker
Worker
Scaling
controller
Single JVM
JVM 1 - seed
Issue #2: how to spin up and shut down nodes?
20. How does the master asks for changes?
class Master extends Actor {
// to add a node
kubernetesController ! AddNode
// to remove a node
kubernetesController ! RemoveNode
}
25. HTTP vs Remote Actor Messaging
• Actor come with built-in elasticity
• Async messaging gives you more control
• Less complexity
• Actor messages do not necessarily need a
response
• HTTP is ubiquitous