# This is the service that should be used by the clients of Dgraph to talk to the cluster.
# apiVersion: v1
# kind: Service
# metadata:
#   name: dgraph-public
#   labels:
#     app: dgraph
# spec:
#   type: LoadBalancer
#   ports:
#   - port: 5080
#     targetPort: 5080
#     name: zero-grpc
#   - port: 6080
#     targetPort: 6080
#     name: zero-http
#   - port: 8080
#     targetPort: 8080
#     name: alpha-http
#   - port: 9080
#     targetPort: 9080
#     name: alpha-grpc
#   - port: 8000
#     targetPort: 8000
#     name: ratel-http
#   selector:
#     app: dgraph
---
# This StatefulSet runs 1 pod with one Zero, one Alpha & one Ratel containers.
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: dgraph
spec:
  serviceName: 'dgraph'
  replicas: 1
  selector:
    matchLabels:
      app: dgraph
  template:
    metadata:
      labels:
        app: dgraph
    spec:
      containers:
        - name: ratel
          image: dgraph/dgraph:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8000
              name: ratel-http
          command:
            - dgraph-ratel
        - name: zero
          image: dgraph/dgraph:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 200m
            requests:
              cpu: 100m
          ports:
            - containerPort: 5080
              name: zero-grpc
            - containerPort: 6080
              name: zero-http
          volumeMounts:
            - name: datadir
              mountPath: /dgraph
          command:
            - bash
            - '-c'
            - |
              set -ex
              dgraph zero --my=$(hostname -f):5080
        - name: alpha
          image: dgraph/dgraph:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              cpu: 200m
            requests:
              cpu: 100m
          ports:
            - containerPort: 8080
              name: alpha-http
            - containerPort: 9080
              name: alpha-grpc
          volumeMounts:
            - name: datadir
              mountPath: /dgraph
          env:
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          command:
            - bash
            - '-c'
            - |
              set -ex
              dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-0.dgraph.${POD_NAMESPACE}.svc.cluster.local:5080
      terminationGracePeriodSeconds: 60
      volumes:
        - name: datadir
          persistentVolumeClaim:
            claimName: datadir
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
    - metadata:
        name: datadir
        annotations:
          volume.alpha.kubernetes.io/storage-class: anything
      spec:
        accessModes:
          - 'ReadWriteOnce'
        resources:
          requests:
            storage: 5Gi
