A trivial implementation of Conway's Game of Life with the help of actors with publishing resulting state in WebSocket connection and in HTTP stream. Basically it creates something like this:
- Conway’s Game of Life streaming with Akka Streams
- GitHub Actions to build your Java/Scala application, test and deploy it to Kubernetes cluster
- Akka
- Akka Http
- Akka Streams (part of Akka itself)
After its start the application will start to publish events as an infinite HTTP-stream from endpoint /stream
or as WebSocket-stream from /ws
.
Could be found in another repo - conway-life-stream-web-client
As a build tool I use gradle and gradle-wrapper
, so you can easily compile and build
application with ./gradlew build
and run with ./gradlew run
.
For the tests I used ScalaTest and Akka native libraries. The tests can be run by the command ./gradlew scalaTest
.
For integration and deployment was used GitHub's framework - GitHub Actions. Workflow source is available there Active workflow could be found there.
For deployment Kubernetes cluster from Azure was used - the cheapest one from the cloud providers. Nice source of info related to cloud provider price comparison - Managed Kubernetes Price Comparison (2020)
Deployment descriptors are available in deployment
sub-folder.
Create the resource group:
az group create --name conwayLifeResourceGroup --location eastus
Create a cluster (it could take some time):
az aks create --resource-group conwayLifeResourceGroup --name conwayLifeAKSCluster --node-count 1 --node-vm-size Standard_B2s --generate-ssh-keys
Get credentials and check functionality:
az aks get-credentials --resource-group conwayLifeResourceGroup --name conwayLifeAKSCluster
kubectl get nodes
Don't forget to store the credentials to future use.
The initial deployment is done by the commands (in deployment
sub-folder):
kubectl apply -f stream-server-deployment.yml
kubectl apply -f stream-server-service.yml
kubectl apply -f stream-server-loadbalancer.yml
The assigned IP can be found with the command:
kubectl describe service/stream-server-loadbalancer | egrep Ingress
Whereas the correctness of work with the command:
curl http://<IP>/health
or simple open that url in you browser.
You should get something like this <h1>Everything is fine :)</h1>
Rolling update is done by the command: kubectl set image deployment/stream-server-deployment conway-life-stream-server=XXXX
,
where XXX is image name (i.e. fedormalyshkin/conway-life-stream-server
)
For this app used fresh enough feature of akka - typed actors (in fact not absolutely fresh, bet has been published officially recently).