GraphQL node setup - documentation says, in a distributed setup, us --alpha

Thanks and I am back :slight_smile:

I converted you docker-compose.yaml file to K8s - and the problem beneath comes down to the same connection to “alpha” - see the command under the graphql I created.
And yes it is me who is doing something wrong with:
dgraph graphql --alpha dgraph-0.alpha.${POD_NAMESPACE}.svc.cluster.local:9080

Trying to connect to(kubectl logs dgraph-0 graphql):
dgraph-0.alpha.default.svc.cluster.local:9080

kubectl logs dgraph-0 graphql
+ dgraph graphql --alpha dgraph-0.alpha.default.svc.cluster.local:9080
[Decoder]: Using assembly version of decoder
I1126 22:20:01.875317       1 init.go:98] 

Dgraph version   : v1.1.0-236-g81b2d73d
Dgraph SHA-256   : 94daafc9de4163861fff4590042a476ba5ca5eaff51f7c8373e02c2fb51f4651
Commit SHA-1     : 81b2d73d
Commit timestamp : 2019-11-18 13:54:20 +1100
Branch           : pawanrawal/graphql-standalone-image
Go version       : go1.13.4

For Dgraph official documentation, visit https://docs.dgraph.io.
For discussions about Dgraph     , visit http://discuss.hypermode.com.
To say hi to the community       , visit https://dgraph.slack.com.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2018 Dgraph Labs, Inc.


I1126 22:20:01.876525       1 run.go:137] Starting GraphQL with Dgraph at: dgraph-0.alpha.default.svc.cluster.local:9080
I1126 22:20:01.877458       1 admin.go:276] Trying to connect to Dgraph at dgraph-0.alpha.default.svc.cluster.local:9080
I1126 22:20:01.879843       1 run.go:169] Bringing up GraphQL HTTP API at 0.0.0.0:9000/graphql
I1126 22:20:01.879862       1 run.go:170] Bringing up GraphiQL web interface for HTTP API at 0.0.0.0:9000/graphiql
I1126 22:20:01.879870       1 run.go:171] Bringing up GraphQL HTTP admin API at 0.0.0.0:9000/admin
I1126 22:20:01.879878       1 run.go:172] Bringing up GraphiQL web interface for HTTP admin API at 0.0.0.0:9000/admin/graphiql
I1126 22:20:21.877900       1 admin.go:276] Trying to connect to Dgraph at dgraph-0.alpha.default.svc.cluster.local:9080
...

The converted k8s.yaml file:

apiVersion: v1
kind: Service
metadata:
  name: dgraph-public
  labels:
    app: dgraph
spec:
  type: LoadBalancer
  ports:
  - port: 9000
    targetPort: 9000
    name: graphql-http
  - 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: graphql
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9000
          name: graphql-http
        command:
          - bash
          - "-c"
          - |
            set -ex        
            dgraph graphql --alpha dgraph-0.alpha.${POD_NAMESPACE}.svc.cluster.local:9080
      - name: ratel
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8000
          name: ratel-http
        command:
          - dgraph-ratel
      - name: zero
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        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/standalone:graphql
        imagePullPolicy: IfNotPresent
        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

All containers is running:

jq -n --arg schema "$(cat schema.graphql)" '{ query: "mutation addSchema($sch: String!) { addSchema(input: { schema: $sch }) { schema { schema } } }", variables: { sch: $schema }}' | curl -X POST -H "Content-Type: application/json" http://<**my-ipaddress-on-k8s**>:9000/admin -d @- | jq -r

Error:

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   741  100   145  100   596   1198   4925 --:--:-- --:--:-- --:--:--  6123
{
  "errors": [
    {
      "message": "Unavailable: Server has not yet connected to Dgraph."
    }
  ],
  "extensions": {
    "requestID": "34ad78ee-bd43-439a-875c-cfafef5baa74"
  }
}

You’re working off of the dgraph-single.yaml config that runs multiple containers in a single pod. It needs a couple more changes to work:

  • The fqdn of the alpha hostname references ${POD_NAMESPACE}, so that environment variable needs to be defined for that container.
  • The service hostname should start with dgraph-0.dgraph.

Here’s the diff:

@@ -52,12 +52,17 @@ spec:
         ports:
         - containerPort: 9000
           name: graphql-http
+        env:
+          - name: POD_NAMESPACE
+            valueFrom:
+              fieldRef:
+                fieldPath: metadata.namespace
         command:
           - bash
           - "-c"
           - |
             set -ex        
-            dgraph graphql --alpha dgraph-0.alpha.${POD_NAMESPACE}.svc.cluster.local:9080
+            dgraph graphql --alpha dgraph-0.dgraph.${POD_NAMESPACE}.svc.cluster.local:9080
       - name: ratel
         image: dgraph/standalone:graphql
         imagePullPolicy: IfNotPresent

and the full k8s config:

apiVersion: v1
kind: Service
metadata:
  name: dgraph-public
  labels:
    app: dgraph
spec:
  type: LoadBalancer
  ports:
  - port: 9000
    targetPort: 9000
    name: graphql-http
  - 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: graphql
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9000
          name: graphql-http
        env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        command:
          - bash
          - "-c"
          - |
            set -ex        
            dgraph graphql --alpha dgraph-0.dgraph.${POD_NAMESPACE}.svc.cluster.local:9080
      - name: ratel
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8000
          name: ratel-http
        command:
          - dgraph-ratel
      - name: zero
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        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/standalone:graphql
        imagePullPolicy: IfNotPresent
        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
1 Like

Hi Daniel

Totally right, it worked - thanks!

Last thing, ratel says “Status Disconnected”. First tought was to find a --flag to set so dgraph-ratel knows where alpha is - but unable to find any ?

      - name: ratel
        image: dgraph/standalone:graphql
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8000
          name: ratel-http
        command:
          - dgraph-ratel

Info: ratel does show up but shows “Choose a version of the Ratel interface” all good starting the latest version and also tried the dev version. But it says as mentioned “Status Disconnected”.

You can set the server URL in Ratel the service endpoint for alpha-http. That won’t be set automatically by Ratel.

Right, like on the page “Enter Dgraph server URL:”

I set the url to: http://<ip-address>:8000/

It is like ratel is working fine, but just need direction to alpha:

kubectl logs dgraph-0 ratel
2019/11/27 09:26:08 Listening on port 8000…

Ahh totally got it - sorry I missed the alpha-http is 8080 and not 8000!!

Thank you Daniel, you have been really good at helping out - I am now able to keep working forward using dgraph.

I must say this a really cool product and I think you guys and girls, have and are making some very nice tech choices - cloud native gRPC and more - keep up the good work!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.