Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

akka/akka-sample-cluster-kubernetes-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

akka-sample-cluster-kubernetes-java

This is an example Maven project showing how to create an Akka Cluster on Kubernetes.

It is not always necessary to use Akka Cluster when deploying an Akka application to Kubernetes: if your application can be designed as independent stateless services that do not need coordination, deploying them on Kubernetes as individual Akka application without Akka Cluster can be a good fit. When state or coordination between nodes is necessary, this is where the Akka Cluster features become interesting and it is worth consider making the nodes form an Akka Cluster.

Kubernetes Instructions

Docker Desktop for Kubernetes

For Windows and Mac users, may be handier to use a Kubernetes cluster on Docker-Desktop. If you use Kubernetes on Docker Desktop, after turning it on, you should first issue:

export KUBECONFIG=~/.kube/config
kubectl config set-context docker-desktop

A script that comprises all steps involved is scripts/test_docker_desktop.sh. To run it, do:

cd akka-sample-cluster-kubernetes-java
scripts/test_docker_desktop.sh

Minikube

If you are using minikube for Kubernetes, please run the included scripts in the scripts directory.

Starting

First, package the application and make it available locally as a docker image:

mvn clean package docker:build

Then akka-cluster.yml should be sufficient to deploy a 2-node Akka Cluster, after creating a namespace for it:

kubectl apply -f kubernetes/namespace.json
kubectl config set-context --current --namespace=appka-1
kubectl apply -f kubernetes/akka-cluster.yml

Finally, create a service so that you can then test https://127.0.0.1:8080 for 'hello world':

kubectl expose deployment appka --type=LoadBalancer --name=appka-service

You can inspect the Akka Cluster membership status with the Cluster HTTP Management.

curl https://127.0.0.1:8558/cluster/members/

To check what you have done in Kubernetes so far, you can do:

kubectl get deployments
kubectl get pods
kubectl get replicasets
kubectl cluster-info dump
kubectl logs appka-79c98cf745-abcdee   # pod name

To wipe everything clean and start over, do:

kubectl delete namespaces appka-1

Running in a real Kubernetes cluster

Publish to a registry the cluster can access e.g. Dockerhub with the kubakka user

The app image must be in a registry the cluster can see. The build.sbt uses DockerHub by default. Use mvn -Ddocker.registry=$DOCKER_REPO_URL/$NAMESPACE if your cluster can't access DockerHub.

To push an image to docker hub run:

mvn -am -pl bootstrap-demo-kubernetes-api package docker:push 

And remove the imagePullPolicy: Never from the deployments. Then you can use the same kubectl commands as described in the Starting section.

How it works

This example uses Akka Cluster Bootstrap to initialize the cluster, using the Kubernetes API discovery mechanism to find peer nodes.

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published