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:

  1. Download and configure the project
  2. Build a Docker image
  3. Deploy with kubectl

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:

  1. Using a command window, clone the tutorial project:

    git clone -b tutorial https://github.com/lightbend/console-akka-cluster-example.git

  2. Change into the example directory:

    cd console-akka-cluster-example

  3. Using any editor, open the project/plugins.sbt file and add a dependency on the sbt-native-packager plugin: addSbtPlugin("com.lightbend.rp" % "sbt-native-packager" % "1.3.22")

  4. In the top level project directory, open build.sbt and add the following lines:

// Enable sbt-native-packager plugin.
enablePlugins(JavaAppPackaging)
dockerBaseImage := "adoptopenjdk/openjdk8"
dockerExposedPorts ++= Seq(2552, 8080, 8558)
  1. Modify libraryDependencies section in build.sbt to look like this:
libraryDependencies ++= Vector(
  "com.typesafe.akka" %% "akka-actor"   % "2.5.23",
  "com.typesafe.akka" %% "akka-cluster" % "2.5.23",
  "com.typesafe.akka" %% "akka-http"    % "10.1.3",
  "com.typesafe.akka" %% "akka-stream"  % "2.5.23",
  "com.typesafe.akka" %% "akka-discovery" % "2.5.23",
  "com.lightbend.akka.management" %% "akka-management" % "1.0.2",
  "com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % "1.0.2",
  "com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % "1.0.2")
  1. Change src/main/resources/application.conf to this:
akka {
  actor {
    provider = "cluster"
  }

  discovery.method = akka-dns

  management {
    http.port = 8558
    cluster.bootstrap {
      contact-point-discovery {
        discovery-method = kubernetes-api
        service-name = "akka-cluster-example"
        required-contact-point-nr = ${REQUIRED_CONTACT_POINT_NR}
      }
    }
  }
}
  1. Create akka-cluster-example.yaml Kubernetes resource file with the following contents:
---
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
    prometheus.io/scrape: "true"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: akka-cluster-example
  template:
    metadata:
      labels:
        app: akka-cluster-example
        prometheus.io/scrape: "true"
    spec:
      containers:
      - name: akka-cluster-example
        image: akka-cluster-example:0.1.0
        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
        readinessProbe:
          httpGet:
            path: "/ready"
            port: management
          periodSeconds: 10
          failureThreshold: 10
          initialDelaySeconds: 20
        livenessProbe:
          httpGet:
            path: "/alive"
            port: management
          periodSeconds: 10
          failureThreshold: 10
          initialDelaySeconds: 20

---
apiVersion: v1
kind: Service
metadata:
  name: akka-cluster-example-svc
  annotations:
    "prometheus.io/scrape": "true"
    "prometheus.io/scheme": http
    "prometheus.io/path": "/metrics"
    "prometheus.io/port": "9091"
spec:
  type: NodePort
  selector:
    app: akka-cluster-example
  ports:
  - name: http
    port: 8080
    targetPort: 8080

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.