apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: cosmos-emulator
  namespace: bytelyst-infra
  labels:
    app: cosmos-emulator
spec:
  replicas: 1
  serviceName: cosmos-emulator
  selector:
    matchLabels:
      app: cosmos-emulator
  template:
    metadata:
      labels:
        app: cosmos-emulator
    spec:
      containers:
      - name: cosmos
        image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
        ports:
        - containerPort: 8081
          name: api
        - containerPort: 1234
          name: explorer
        env:
        - name: AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE
          value: "true"
        - name: ENABLE_EXPLORER
          value: "true"
        - name: AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE
          value: "0.0.0.0"
        - name: PROTOCOL
          value: "http"
        resources:
          requests:
            cpu: "500m"
            memory: "2Gi"
          limits:
            cpu: "2000m"
            memory: "3Gi"
        readinessProbe:
          httpGet:
            path: /_explorer/emulator.pem
            port: 8081
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 15
          timeoutSeconds: 5
        volumeMounts:
        - name: cosmos-data
          mountPath: /tmp/cosmos/appdata
  volumeClaimTemplates:
  - metadata:
      name: cosmos-data
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
  name: cosmos-emulator
  namespace: bytelyst-infra
spec:
  selector:
    app: cosmos-emulator
  ports:
  - name: api
    port: 8081
    targetPort: 8081
  - name: explorer
    port: 1234
    targetPort: 1234
---
# NodePort for external access to Cosmos Explorer
apiVersion: v1
kind: Service
metadata:
  name: cosmos-emulator-external
  namespace: bytelyst-infra
spec:
  type: NodePort
  selector:
    app: cosmos-emulator
  ports:
  - name: explorer
    port: 1234
    targetPort: 1234
    nodePort: 1234
