apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: replicator
  labels:
    app: replicator
spec:
  replicas: 3
  serviceName: "replicator-grpc-service"
  podManagementPolicy: Parallel
  selector:
    matchLabels:
      app: replicator
  template:
    metadata:
      labels:
        app: replicator
    spec:
      affinity:
        podAntiAffinity:
          #          requiredDuringSchedulingIgnoredDuringExecution:
          #            - labelSelector:
          #                matchExpressions:
          #                  - key: app
          #                    operator: In
          #                    values:
          #                      - replicator
          #              topologyKey: topology.kubernetes.io/zone
          preferredDuringSchedulingIgnoredDuringExecution:
            - podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - replicator
                topologyKey: topology.kubernetes.io/zone
              weight: 100
      containers:
        - name: replicator
          image: olgnet/replicator:latest
          imagePullPolicy: Always
          command: [ "java" ]
          args: [
              "--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED",
              "-Dio.netty.tryReflectionSetAccessible=true",
              "-XX:MaxGCPauseMillis=50",
              "-Xms4536M", "-Xmx5536M", "-jar", "/app.jar",
              "--maxConcurrentSubmits", "500",
              "--protocol", "ATLAS",
              "--nodes", "replicator-0.replicator-grpc-service.default.svc.cluster.local:6545,replicator-1.replicator-grpc-service.default.svc.cluster.local:6545,replicator-2.replicator-grpc-service.default.svc.cluster.local:6545",
              "--rocksDbFile", "/data"
          ]
          ports:
            - containerPort: 8000
            - containerPort: 6545
          volumeMounts:
            - mountPath: /data
              name: data
          resources:
            limits:
              cpu: 3000m
              memory: 6Gi
            requests:
              cpu: 3000m
              memory: 6Gi
          livenessProbe:
            httpGet:
              path: /health
              port: 8000
            initialDelaySeconds: 5
            periodSeconds: 5
            failureThreshold: 10
          readinessProbe:
            httpGet:
              path: /health
              port: 8000
            initialDelaySeconds: 5
            periodSeconds: 5
            failureThreshold: 10
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi