version: "3.9"

services:
  kv-node-1:
    image: quay.io/coreos/etcd:v3.5.13
    container_name: kv-node-1
    restart: unless-stopped
    command:
      - /usr/local/bin/etcd
      - --name=kv-node-1
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://kv-node-1:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://kv-node-1:2380
      - --initial-cluster=kv-node-1=http://kv-node-1:2380,kv-node-2=http://kv-node-2:2380,kv-node-3=http://kv-node-3:2380
      - --initial-cluster-token=kv-store-prod
      - --initial-cluster-state=new
      - --auto-compaction-retention=1h
      - --quota-backend-bytes=8589934592
    ports:
      - "2379:2379"
    volumes:
      - kv-node-1-data:/etcd-data
    networks:
      - kv-cluster
    healthcheck:
      test: ["CMD", "etcdctl", "--endpoints=http://127.0.0.1:2379", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

  kv-node-2:
    image: quay.io/coreos/etcd:v3.5.13
    container_name: kv-node-2
    restart: unless-stopped
    command:
      - /usr/local/bin/etcd
      - --name=kv-node-2
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://kv-node-2:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://kv-node-2:2380
      - --initial-cluster=kv-node-1=http://kv-node-1:2380,kv-node-2=http://kv-node-2:2380,kv-node-3=http://kv-node-3:2380
      - --initial-cluster-token=kv-store-prod
      - --initial-cluster-state=new
      - --auto-compaction-retention=1h
      - --quota-backend-bytes=8589934592
    ports:
      - "2381:2379"
    volumes:
      - kv-node-2-data:/etcd-data
    networks:
      - kv-cluster
    healthcheck:
      test: ["CMD", "etcdctl", "--endpoints=http://127.0.0.1:2379", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

  kv-node-3:
    image: quay.io/coreos/etcd:v3.5.13
    container_name: kv-node-3
    restart: unless-stopped
    command:
      - /usr/local/bin/etcd
      - --name=kv-node-3
      - --data-dir=/etcd-data
      - --listen-client-urls=http://0.0.0.0:2379
      - --advertise-client-urls=http://kv-node-3:2379
      - --listen-peer-urls=http://0.0.0.0:2380
      - --initial-advertise-peer-urls=http://kv-node-3:2380
      - --initial-cluster=kv-node-1=http://kv-node-1:2380,kv-node-2=http://kv-node-2:2380,kv-node-3=http://kv-node-3:2380
      - --initial-cluster-token=kv-store-prod
      - --initial-cluster-state=new
      - --auto-compaction-retention=1h
      - --quota-backend-bytes=8589934592
    ports:
      - "2382:2379"
    volumes:
      - kv-node-3-data:/etcd-data
    networks:
      - kv-cluster
    healthcheck:
      test: ["CMD", "etcdctl", "--endpoints=http://127.0.0.1:2379", "endpoint", "health"]
      interval: 10s
      timeout: 5s
      retries: 5

networks:
  kv-cluster:
    driver: bridge

volumes:
  kv-node-1-data:
  kv-node-2-data:
  kv-node-3-data: