apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: scylla
  labels:
    app: scylla
spec:
  serviceName: scylla
  replicas: 3
  selector:
    matchLabels:
      app: scylla
  template:
    metadata:
      labels:
        app: scylla
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - scylla
            topologyKey: kubernetes.io/hostname
      containers:
      - name: scylla
        env:
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: scylladb/scylla:4.2.0
        args: ["--developer-mode", "0", "--memory", "4G", "--overprovisioned", "1", "--seeds", "scylla-0.scylla", "--smp", "4"]
        ports:
        - containerPort: 7000
          name: intra-node
        - containerPort: 7001
          name: tls-intra-node
        - containerPort: 7199
          name: jmx
        - containerPort: 9042
          name: cql
        securityContext:
          capabilities:
            add:
            - IPC_LOCK
        lifecycle:
          preStop:
            exec:
              command: ["/bin/sh", "-c", "PID=$(pidof scylla) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
        readinessProbe:
          exec:
            command:
            - /bin/bash
            - -c
            - exec
            - /opt/ready-probe.sh
          initialDelaySeconds: 60
          timeoutSeconds: 5
        volumeMounts:
        - name: scylla-data
          mountPath: /var/lib/scylla
        - name: scylla-ready-probe
          mountPath: /opt/ready-probe.sh
          subPath: ready-probe.sh
      initContainers:
      - name: increase-fs-aio-nr-max
        image: busybox
        command: ["sysctl", "-w", "fs.aio-max-nr=262144"]
        securityContext:
          privileged: true
      volumes:
      - name: scylla-ready-probe
        configMap:
          name: scylla
  volumeClaimTemplates:
  - metadata:
      name: scylla-data
    spec:
      accessModes:
      - "ReadWriteOnce"
      resources:
        requests:
          storage: 48Gi
      storageClassName: do-block-storage-xfs
