0

I'm trying to run Hasura locally in K8s. I have go 2 deployment files and 2 svc files respectively.

# Hasura Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hasura
    hasuraService: custom
  name: hasura
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hasura
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: hasura
    spec:
      containers:
      - image: hasura/graphql-engine:v2.8.0
        imagePullPolicy: IfNotPresent
        name: hasura
        env:
        - name: HASURA_GRAPHQL_DATABASE_URL
          value: postgres://postgres:postgres@kubernetes.docker.internal:5432/postgres
        - name: HASURA_GRAPHQL_ADMIN_SECRET
          value: TopSecret
        ## enable the console served by server
        - name: HASURA_GRAPHQL_ENABLE_CONSOLE
          value: "true"
        ## enable debugging mode. It is recommended to disable this in production
        - name: HASURA_GRAPHQL_DEV_MODE
          value: "true"
        ports:
        - containerPort: 8080
          protocol: TCP
        resources: {}

# Hasura Service

apiVersion: v1
kind: Service
metadata:
  labels:
    app: hasura
  name: hasura
  namespace: default
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  selector:
    app: hasura
  type: LoadBalancer

#Postgres Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: db
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: db
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        io.kompose.service: db
    spec:
      containers:
        - env:
            - name: POSTGRES_DB
              value: myDB
            - name: POSTGRES_HOST
              value: localhost
            - name: POSTGRES_PASSWORD
              value: somePassword
            - name: POSTGRES_USER
              value: postgres
          image: my_image
          imagePullPolicy: Never
          name: db
          ports:
            - containerPort: 5432
          resources: {}
          volumeMounts:
            - mountPath: /var/lib/postgresql/data/
              name: postgres-pv-storage
      restartPolicy: Always
      volumes:
        - name: postgres-pv-storage
          persistentVolumeClaim:
            claimName: postgres-pv-claim
status: {}
# Postgres Service

apiVersion: v1
kind: Service
metadata:
  labels:
    io.kompose.service: db
  name: db
  namespace: default
spec:
  type: ExternalName
  # https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
  externalName: kubernetes.docker.internal
  ports:
    - name: "5432"
      port: 5432
      targetPort: 5432
status:
  loadBalancer: {}

However, Hasura service doensn't seem to start. Log says:

$ kubectl logs hasura-7d5ddd9564-jzcxl
{"internal":"connection to server at \"kubernetes.docker.internal\" (192.167.62.4), port 5432 failed: Connection refused\n\tIs the server running on that host and accepting TCP/IP connections?\n","path":"$","error":"connection error","code":"postgres-error"}

Any idea on how to fix it?

HelmBurger
  • 1,168
  • 5
  • 15
  • 35
  • The PostgresService is for an External Service and entirely wrong. I strongly recommend using https://bitnami.com/stack/postgresql/helm – Markus W Mahlberg Jun 21 '22 at 09:53

1 Answers1

1

I wasn't able to solve the specific error I was getting but I did successfully manage to use Helm charts to implement Postgres in K8s. This overcame the error I was getting in first place.

This is what I'm using for Postgres: https://github.com/helm/charts/tree/master/stable/postgresql

And this is what I'm using for Hasura: https://hasura.io/docs/latest/graphql/core/deployment/deployment-guides/kubernetes/

If you run into EXTERNAL-IP being stuck at pending, remember to run minikube tunnel. This is because loadBalancer used in the Hasura service is for deployments on Cloud, not local.

HelmBurger
  • 1,168
  • 5
  • 15
  • 35