Run the Example Akka App
To make sure that your environment is set up correctly, install the example app and use Lightbend Platform helper libraries to deploy it to Minikube. The main steps include:
Download and configure the project
Clone the example, configure it to use the sbt-native-packager
to build a docker image and add Lightbend Platform service discovery libraries that will allow Akka Cluster to run inside Kubernetes:
-
Using a command window, clone the tutorial project:
git clone -b tutorial https://github.com/lightbend/console-akka-cluster-example.git
-
Change into the example directory:
cd console-akka-cluster-example
-
Using any editor, open the
project/plugins.sbt
file and add a dependency on thesbt-native-packager
plugin:addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.8.1")
-
In the top level project directory, open
build.sbt
and add the following lines:// Enable sbt-native-packager plugin. enablePlugins(JavaAppPackaging) dockerBaseImage := "docker.io/library/adoptopenjdk:11-jre-hotspot" dockerExposedPorts ++= Seq(2551, 8080, 8558)
-
Modify
libraryDependencies
section inbuild.sbt
to look like this:val AkkaManagementVersion = "1.0.10" libraryDependencies ++= Seq( // Akka HTTP dependencies "com.typesafe.akka" %% "akka-http" % AkkaHttpVersion, "com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion, // Akka Dependencies "com.typesafe.akka" %% "akka-slf4j" % AkkaVersion, "com.typesafe.akka" %% "akka-actor" % AkkaVersion, "com.typesafe.akka" %% "akka-cluster" % AkkaVersion, "com.typesafe.akka" %% "akka-stream" % AkkaVersion, "com.typesafe.akka" %% "akka-discovery" % AkkaVersion, // Logback dependencies "ch.qos.logback" % "logback-classic" % "1.2.3", // Akka Management dependencies "com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion, "com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion, "com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % AkkaManagementVersion )
-
Change
src/main/resources/application.conf
to this:akka { loglevel = DEBUG actor.provider = cluster remote.artery { canonical.port = 2551 } # See more details about Cluster usage on Akka docs: # https://doc.akka.io/docs/akka/current/cluster-usage.html cluster { downing-provider-class = "akka.cluster.sbr.SplitBrainResolverProvider" shutdown-after-unsuccessful-join-seed-nodes = 120s sharding { least-shard-allocation-strategy.rebalance-absolute-limit = 20 } } # See more details about Akka Management on Akka docs: # https://doc.akka.io/docs/akka-management/current/akka-management.html management { http { port = 8558 } # See more details about Cluster Bootstrap on Akka docs: # https://doc.akka.io/docs/akka-management/current/bootstrap/index.html cluster.bootstrap { contact-point-discovery { discovery-method = kubernetes-api service-name = "akka-cluster-example" required-contact-point-nr = ${REQUIRED_CONTACT_POINT_NR} } } } }
-
Create
akka-cluster-example.yaml
Kubernetes resource file with the following contents:
# See Akka docs for more about how to configure your Akka Cluster to
# run on Kubernetes:
# https://doc.akka.io/docs/akka-management/current/bootstrap/kubernetes-api.html
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-pods
subjects:
- kind: ServiceAccount
name: default
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: akka-cluster-example
labels:
app: akka-cluster-example
spec:
replicas: 3
selector:
matchLabels:
app: akka-cluster-example
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: akka-cluster-example
actorSystemName: akka-cluster-example
prometheus.io/scrape: "true"
spec:
containers:
- name: akka-cluster-example
image: akka-cluster-example:0.1.5
livenessProbe:
httpGet:
path: "/alive"
port: management
readinessProbe:
httpGet:
path: "/ready"
port: management
env:
- name: REQUIRED_CONTACT_POINT_NR
value: "3"
- name: AKKA_CLUSTER_BOOTSTRAP_SERVICE_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: "metadata.labels['app']"
ports:
- name: remoting
containerPort: 2552
- name: http
containerPort: 8080
- name: management
containerPort: 8558
- name: metrics
containerPort: 9091
---
apiVersion: v1
kind: Service
metadata:
name: akka-cluster-example-svc
annotations:
"prometheus.io/scrape": "true"
spec:
type: NodePort
selector:
app: akka-cluster-example
ports:
- name: http
port: 8080
targetPort: 8080
- name: metrics
port: 9091
targetPort: 9091
Build a Docker image
Check to make sure that Minikube is running and you have access to the Lightbend Console. (See the Installation Guide if you have any issues.) Then, build a docker image for your application and publish it using the following commands:
eval $(minikube docker-env)
sbt docker:publishLocal
Deploy with kubectl
Now you can deploy the app using kubectl
:
kubectl apply -f akka-cluster-example.yaml
Check the app
After a minute, your application should be up with three cluster members. You can check the status of the application with kubectl
:
kubectl get pod
If there are any errors, you can investigate further with kubectl commands such as kubectl describe pod <pod-name>
.
You should now be able to see the app as a Workload in the Minikube dashboard and as a Pod in the Lightbend Console. As a reminder, if you don’t have the Console open, find the minikube IP:
minikube ip
Using the IP, view the Lightbend Console at minikube-ip:30080
. The default should be http://192.168.99.100:30080
.
Now that you are sure that your environment is configured correctly, instrument the app with Telemetry.