github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/contrib/config/kubernetes/dgraph-ha/dgraph-ha.yaml (about)

     1  # This highly available config creates 3 Dgraph Zeros, 3 Dgraph
     2  # Alphas with 3 replicas, and 1 Ratel UI client. The Dgraph cluster
     3  # will still be available to service requests even when one Zero
     4  # and/or one Alpha are down.
     5  #
     6  # There are 4 public services exposed, users can use:
     7  #       dgraph-zero-public - To load data using Live & Bulk Loaders
     8  #       dgraph-alpha-public - To connect clients and for HTTP APIs
     9  #       dgraph-ratel-public - For Dgraph UI
    10  #       dgraph-alpha-x-http-public - Use for debugging & profiling
    11  apiVersion: v1
    12  kind: Service
    13  metadata:
    14    name: dgraph-zero-public
    15    labels:
    16      app: dgraph-zero
    17  spec:
    18    type: LoadBalancer
    19    ports:
    20    - port: 5080
    21      targetPort: 5080
    22      name: zero-grpc
    23    - port: 6080
    24      targetPort: 6080
    25      name: zero-http
    26    selector:
    27      app: dgraph-zero
    28  ---
    29  apiVersion: v1
    30  kind: Service
    31  metadata:
    32    name: dgraph-alpha-public
    33    labels:
    34      app: dgraph-alpha
    35  spec:
    36    type: LoadBalancer
    37    ports:
    38    - port: 8080
    39      targetPort: 8080
    40      name: alpha-http
    41    - port: 9080
    42      targetPort: 9080
    43      name: alpha-grpc
    44    selector:
    45      app: dgraph-alpha
    46  ---
    47  # This service is created in-order to debug & profile a specific alpha.
    48  # You can create one for each alpha that you need to profile.
    49  # For a more general HTTP APIs use the above service instead.
    50  apiVersion: v1
    51  kind: Service
    52  metadata:
    53    name: dgraph-alpha-0-http-public
    54    labels:
    55      app: dgraph-alpha
    56  spec:
    57    type: LoadBalancer
    58    ports:
    59    - port: 8080
    60      targetPort: 8080
    61      name: alpha-http
    62    selector:
    63      statefulset.kubernetes.io/pod-name: dgraph-alpha-0
    64  ---
    65  apiVersion: v1
    66  kind: Service
    67  metadata:
    68    name: dgraph-ratel-public
    69    labels:
    70      app: dgraph-ratel
    71  spec:
    72    type: LoadBalancer
    73    ports:
    74    - port: 8000
    75      targetPort: 8000
    76      name: ratel-http
    77    selector:
    78      app: dgraph-ratel
    79  ---
    80  # This is a headless service which is necessary for discovery for a dgraph-zero StatefulSet.
    81  # https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset
    82  apiVersion: v1
    83  kind: Service
    84  metadata:
    85    name: dgraph-zero
    86    labels:
    87      app: dgraph-zero
    88  spec:
    89    ports:
    90    - port: 5080
    91      targetPort: 5080
    92      name: zero-grpc
    93    clusterIP: None
    94    selector:
    95      app: dgraph-zero
    96  ---
    97  # This is a headless service which is necessary for discovery for a dgraph-alpha StatefulSet.
    98  # https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/#creating-a-statefulset
    99  apiVersion: v1
   100  kind: Service
   101  metadata:
   102    name: dgraph-alpha
   103    labels:
   104      app: dgraph-alpha
   105  spec:
   106    ports:
   107    - port: 7080
   108      targetPort: 7080
   109      name: alpha-grpc-int
   110    clusterIP: None
   111    selector:
   112      app: dgraph-alpha
   113  ---
   114  # This StatefulSet runs 3 Dgraph Zero.
   115  apiVersion: apps/v1
   116  kind: StatefulSet
   117  metadata:
   118    name: dgraph-zero
   119  spec:
   120    serviceName: "dgraph-zero"
   121    replicas: 3
   122    selector:
   123      matchLabels:
   124        app: dgraph-zero
   125    template:
   126      metadata:
   127        labels:
   128          app: dgraph-zero
   129      spec:
   130        affinity:
   131          podAntiAffinity:
   132            preferredDuringSchedulingIgnoredDuringExecution:
   133            - weight: 100
   134              podAffinityTerm:
   135                labelSelector:
   136                  matchExpressions:
   137                  - key: app
   138                    operator: In
   139                    values:
   140                    - dgraph-zero
   141                topologyKey: kubernetes.io/hostname
   142        containers:
   143        - name: zero
   144          image: dgraph/dgraph:latest
   145          imagePullPolicy: IfNotPresent
   146          ports:
   147          - containerPort: 5080
   148            name: zero-grpc
   149          - containerPort: 6080
   150            name: zero-http
   151          volumeMounts:
   152          - name: datadir
   153            mountPath: /dgraph
   154          env:
   155            - name: POD_NAMESPACE
   156              valueFrom:
   157                fieldRef:
   158                  fieldPath: metadata.namespace
   159          command:
   160            - bash
   161            - "-c"
   162            - |
   163              set -ex
   164              [[ `hostname` =~ -([0-9]+)$ ]] || exit 1
   165              ordinal=${BASH_REMATCH[1]}
   166              idx=$(($ordinal + 1))
   167              if [[ $ordinal -eq 0 ]]; then
   168                exec dgraph zero --my=$(hostname -f):5080 --idx $idx --replicas 3
   169              else
   170                exec dgraph zero --my=$(hostname -f):5080 --peer dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080 --idx $idx --replicas 3
   171              fi
   172        terminationGracePeriodSeconds: 60
   173        volumes:
   174        - name: datadir
   175          persistentVolumeClaim:
   176            claimName: datadir
   177    updateStrategy:
   178      type: RollingUpdate
   179    volumeClaimTemplates:
   180    - metadata:
   181        name: datadir
   182        annotations:
   183          volume.alpha.kubernetes.io/storage-class: anything
   184      spec:
   185        accessModes:
   186          - "ReadWriteOnce"
   187        resources:
   188          requests:
   189            storage: 5Gi
   190  ---
   191  # This StatefulSet runs 3 replicas of Dgraph Alpha.
   192  apiVersion: apps/v1
   193  kind: StatefulSet
   194  metadata:
   195    name: dgraph-alpha
   196  spec:
   197    serviceName: "dgraph-alpha"
   198    replicas: 3
   199    selector:
   200      matchLabels:
   201        app: dgraph-alpha
   202    template:
   203      metadata:
   204        labels:
   205          app: dgraph-alpha
   206      spec:
   207        affinity:
   208          podAntiAffinity:
   209            preferredDuringSchedulingIgnoredDuringExecution:
   210            - weight: 100
   211              podAffinityTerm:
   212                labelSelector:
   213                  matchExpressions:
   214                  - key: app
   215                    operator: In
   216                    values:
   217                    - dgraph-alpha
   218                topologyKey: kubernetes.io/hostname
   219        # Initializing the Alphas:
   220        #
   221        # You may want to initialize the Alphas with data before starting, e.g.
   222        # with data from the Dgraph Bulk Loader: https://docs.dgraph.io/deploy/#bulk-loader.
   223        # You can accomplish by uncommenting this initContainers config. This
   224        # starts a container with the same /dgraph volume used by Alpha and runs
   225        # before Alpha starts.
   226        #
   227        # You can copy your local p directory to the pod's /dgraph/p directory
   228        # with this command:
   229        #
   230        #    kubectl cp path/to/p dgraph-alpha-0:/dgraph/ -c init-alpha
   231        #    (repeat for each alpha pod)
   232        #
   233        # When you're finished initializing each Alpha data directory, you can signal
   234        # it to terminate successfully by creating a /dgraph/doneinit file:
   235        #
   236        #    kubectl exec dgraph-alpha-0 -c init-alpha touch /dgraph/doneinit
   237        #
   238        # Note that pod restarts cause re-execution of Init Containers. Since
   239        # /dgraph is persisted across pod restarts, the Init Container will exit
   240        # automatically when /dgraph/doneinit is present and proceed with starting
   241        # the Alpha process.
   242        #
   243        # Tip: StatefulSet pods can start in parallel by configuring
   244        # .spec.podManagementPolicy to Parallel:
   245        #
   246        #     https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees
   247        #
   248        # initContainers:
   249        #   - name: init-alpha
   250        #     image: dgraph/dgraph:latest
   251        #     command:
   252        #       - bash
   253        #       - "-c"
   254        #       - |
   255        #         echo "Write to /dgraph/doneinit when ready."
   256        #         until [ -f /dgraph/doneinit ]; do sleep 2; done
   257        #     volumeMounts:
   258        #       - name: datadir
   259        #         mountPath: /dgraph
   260        containers:
   261        - name: alpha
   262          image: dgraph/dgraph:latest
   263          imagePullPolicy: IfNotPresent
   264          ports:
   265          - containerPort: 7080
   266            name: alpha-grpc-int
   267          - containerPort: 8080
   268            name: alpha-http
   269          - containerPort: 9080
   270            name: alpha-grpc
   271          volumeMounts:
   272          - name: datadir
   273            mountPath: /dgraph
   274          env:
   275            # This should be the same namespace as the dgraph-zero
   276            # StatefulSet to resolve a Dgraph Zero's DNS name for
   277            # Alpha's --zero flag.
   278            - name: POD_NAMESPACE
   279              valueFrom:
   280                fieldRef:
   281                  fieldPath: metadata.namespace
   282          command:
   283            - bash
   284            - "-c"
   285            - |
   286              set -ex
   287              dgraph alpha --my=$(hostname -f):7080 --lru_mb 2048 --zero dgraph-zero-0.dgraph-zero.${POD_NAMESPACE}.svc.cluster.local:5080
   288        terminationGracePeriodSeconds: 600
   289        volumes:
   290        - name: datadir
   291          persistentVolumeClaim:
   292            claimName: datadir
   293    updateStrategy:
   294      type: RollingUpdate
   295    volumeClaimTemplates:
   296    - metadata:
   297        name: datadir
   298        annotations:
   299          volume.alpha.kubernetes.io/storage-class: anything
   300      spec:
   301        accessModes:
   302          - "ReadWriteOnce"
   303        resources:
   304          requests:
   305            storage: 5Gi
   306  ---
   307  apiVersion: apps/v1
   308  kind: Deployment
   309  metadata:
   310    name: dgraph-ratel
   311    labels:
   312      app: dgraph-ratel
   313  spec:
   314    selector:
   315      matchLabels:
   316        app: dgraph-ratel
   317    template:
   318      metadata:
   319        labels:
   320          app: dgraph-ratel
   321      spec:
   322        containers:
   323        - name: ratel
   324          image: dgraph/dgraph:latest
   325          ports:
   326          - containerPort: 8000
   327          command:
   328            - dgraph-ratel