How to deploy Akka Cluster to Kubernetes?

9/30/2019

I wrote small application that support clustering with Akka Cluster. I want to deploy it to Kubernetes with support scaling. This is my docker-compose.yml file:

version: '3.5'

networks:
  cluster-network:

services:
  seed:
    networks:
      - cluster-network
    image: akka-cluster-server
    ports:
      - '2552:2552'
      - '8000:8000'
    environment:
      SERVER_IP: 0.0.0.0
      CLUSTER_IP: seed
      CLUSTER_SEED_IP: seed

  node1:
    networks:
      - cluster-network
    image: akka-cluster-server
    ports:
      - '8001:8000'
    environment:
      SERVER_IP: 0.0.0.0
      CLUSTER_IP: node1
      CLUSTER_PORT: 1600
      CLUSTER_SEED_IP: seed
      CLUSTER_SEED_PORT: 2552

  node2:
    networks:
      - cluster-network
    image: akka-cluster-server
    ports:
      - '8002:8000'
    environment:
      SERVER_IP: 0.0.0.0
      CLUSTER_IP: node2
      CLUSTER_PORT: 1600
      CLUSTER_SEED_IP: seed
      CLUSTER_SEED_PORT: 2552

There is three instances that share network among themselves. Note that node1 and node2 use seed's DNS name to connect. I wrote simple deployment and service.

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: akka-cluster
spec:
  selector:
    matchLabels:
      app: akka-cluster
  replicas: 2
  template:
    metadata:
      labels:
        app: akka-cluster
    spec:
      containers:
      - name: server-seed
        image: akka-cluster-server
        imagePullPolicy: Never
        ports:
        - containerPort: 8000
        - containerPort: 2552
        env:
        - name: SERVER_IP
          value: 0.0.0.0
        - name: CLUSTER_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: CLUSTER_SEED_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: CLUSTER_PORT
          value: "1600"
        - name: CLUSTER_SEED_PORT
          value: "2552"

Service:

apiVersion: v1
kind: Service
metadata:
  name: akka-cluster-service
spec:
  type: LoadBalancer
  selector:
    app: akka-cluster
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8000

Note that in this case containers will connect to self (CLUSTER_SEED_IP) instead of seed node when you will scale replicas.

How to correct translate my docker-compose.yml to Kubernetes deployment/service?

-- Valeriy
akka-cluster
kubernetes

1 Answer

9/30/2019

To "translate" docker-compose correctly you should create two sets of deployment +service: one for seed and another for nodes.

If you need to list all the instances as seeds then probably better way would be to implement via statefulset. You can check this for example https://github.com/IBM/Akka-cluster-deploy-kubernetes/blob/master/deploy/kubernetes/resources/myapp/myapp-statefulset.json

-- abinet
Source: StackOverflow