apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: typesense
  namespace: typesense
  labels:
    service: typesense
    app: typesense
spec:
  serviceName: ts
  podManagementPolicy: Parallel
  replicas: 3
  selector:
    matchLabels:
      service: typesense
      app: typesense
  template:
    metadata:
      labels:
        service: typesense
        app: typesense
    spec:
      securityContext:
        fsGroup: 2000
        runAsUser: 10000
        runAsGroup: 3000
        runAsNonRoot: true
      terminationGracePeriodSeconds: 300
      containers:
      - name: typesense
        image: typesense/typesense:27.0
        command:
          - "/opt/typesense-server"
          - "-d"
          - "/usr/share/typesense/data"
          - "-a"
          - "$(API_KEY)"
          - "--api-port"
          - "8108"
          - "--peering-port"
          - "8107"
          - "--peers"
          - "$(POD_NAME)-0.ts.typesense.svc.cluster.local:8107,$(POD_NAME)-1.ts.typesense.svc.cluster.local:8107,$(POD_NAME)-2.ts.typesense.svc.cluster.local:8107"
          - '--reset-peers-on-error'
        ports:
        - containerPort: 8108
          name: http
        resources:
          requests:
            memory: "2.5Gi"
            cpu: "1500m"
        volumeMounts:
        - name: data
          mountPath: /usr/share/typesense/data
        env: 
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: API_KEY
          valueFrom:
            secretKeyRef:
              name: typesense-api-key  
              key: api-key   
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: gp2
      resources:
        requests:
          storage: 10Gi
