Cassandra on Docker Swarm

Can someone please post a link to a document or article on installing Cassandra on Docker Swarm?

I think you’ll have to write it :slight_smile:

I run 3 Cassandra instances from docker stack deploy command that reads the following YML file:

version: '3'
services:
  cassandra-1:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra1
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-1
    volumes:
    - volume1:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
  cassandra-2:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra2
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-2
      CASSANDRA_SEEDS: cassandra-1
    depends_on:
      - cassandra-1
    volumes:
    - volume2:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
  cassandra-3:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra3
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-3
      CASSANDRA_SEEDS: cassandra-1
    depends_on:
      - cassandra-2
    volumes:
    - volume3:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
volumes:
  volume1:
    external:
        name: cassandra1-vol
  volume2:
    external:
        name: cassandra2-vol
  volume3:
    external:
        name: cassandra3-vol
networks:
  default:
    external:
       name: cassandra-net

Alternatively, each instance could be run individually from its docker service create counterpart with similar parameters.

As a side note, the custom node.labels.db==cassandra label is required in my setup because of the tight coupling with the volumes in a 3 managers + 5 workers cluster.

For Cassandra, the current docker volume plugin such as folcker, rexray, etc, could not help, as they could not setup the membership among Cassandra members. azaars’s solution is a reasonable way to setup Cassandra on Docker Swarm. While, if the node goes down, one Cassandra member will disappear. You would need additional work to bring up another node, and join the current Cassandra cluster. Cassandra will then recover data automatically.

FireCamp is a recent open source project aims to automate the installation and management of the stateful services, including Cassandra, on Docker Swarm. While, currently it only supports installing the stateful services for Docker Swarm on AWS. Hope it could help your case.

Hi Azzars,

You have created 3 services for Cassandra that means it is fixed to 3 only. what if you want scale up the Cassandra to 4 or 5 ?

$ docker service create --replicas 3 --name cassandra --update-delay 10m cassandra

$ docker service ps cassandra
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
tanytkx5if1g cassandra.1 cassandra:latest pc4 Running Running 5 minutes ago
thg7w2oe25os cassandra.2 cassandra:latest pc2 Running Running 6 minutes ago
i88mbrv12x26 cassandra.3 cassandra:latest pc3 Running Running 5 minutes ago

$ docker service inspect --pretty cassandra
ID: r9dwiuuffb4a5v0105a5bhail
Name: cassandra
Service Mode: Replicated
Replicas: 3
Placement:
UpdateConfig:
Parallelism: 1
Delay: 10m0s
On failure: pause
Max failure ratio: 0
ContainerSpec:
Image: cassandra:latest@sha256:a78df4f39a2024a286d30ec3d6f6acf428924e8063b15fa22ea1ed3b3304bd6b
Resources:
Endpoint Mode: vip

network “cassandra-net” is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed

how to create the cassandra-net?