Improve SBR’s decision process

Deploying on Kubernetes opens the door to use Kubernetes-provided mechanisms for decision-making. The Akka Split-Brain Resolver new tab can use a Lease new tab backed by Kubernetes to control which side of a cluster may remain up during a split-brain scenario.

This How-To guide assumes you are developing an application based on Akka Cluster and already enabled and configured Akka Cluster’s Split-Brain Resolver.

Add the Kubernetes Lease dependency

First make sure your application includes the SBR and the Kubernetes Lease dependencies on the build:

Java
pom.xml:
<dependency>
    <groupId>com.lightbend.akka.management</groupId>
    <artifactId>akka-lease-kubernetes_${scala.binary.version}</artifactId>
</dependency>
Scala
build.sbt:
"com.lightbend.akka.management" %% "akka-lease-kubernetes" % AkkaManagementVersion

Setup your Kubernetes Cluster and AkkaMicroservice

When installing the Akka Operator on your Kubernetes cluster using the Helm chart you will also install the Akka Kubernetes Lease CRD.

Once the CRD is installed, you can configure your Akka Microservice to back the SBR implementation with a Kubernetes Lease enabling it on the AkkaMicroservice CR:

kubernetes/shopping-cart-service-cr.yml
apiVersion: akka.lightbend.com/v1
kind: AkkaMicroservice
metadata:
  name: shopping-cart-service
spec:
  image: <image>
  splitBrainResolver:
    useKubernetesLease: true (1)
1 When using a kubernetes lease as a backend for the Split-Brain Resolver, the operator will name the lease <metadata.name>-akka-sbr. In the example above, the lease will be named shopping-cart-service-akka-sbr.