简体   繁体   English

Kubernetes Pod 无法使用 Hasura 映像连接到本地 postgres 服务器

[英]Kubernetes Pod can't connect to local postgres server with Hasura image

I'm following this tutorial to connect a hasura kubernetes pod to my local postgres server.我正在按照本教程将 hasura kubernetes pod 连接到我的本地 postgres 服务器。

When I create the deployment, the pod's container fails to connect to postgres (CrashLoopBackOff and keeps retrying), but doesn't give any reason why.当我创建部署时,pod 的容器无法连接到 postgres(CrashLoopBackOff 并不断重试),但没有给出任何原因。 Here are the logs:以下是日志:

{"type":"pg-client","timestamp":"2020-05-03T06:22:21.648+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(0)."}}

My deployment.yaml:我的部署。yaml:

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:v1.2.0
        imagePullPolicy: IfNotPresent
        name: hasura
        env:
        - name: HASURA_GRAPHQL_DATABASE_URL
          value: postgres://USER:@localhost:5432/my_db
        - name: HASURA_GRAPHQL_ENABLE_CONSOLE
          value: "true"
        ports:
        - containerPort: 8080
          protocol: TCP
        resources: {}

I'm using postgres://USER:@localhost:5432/MY_DB as the postgres url - is "localhost" the correct address here?我使用postgres://USER:@localhost:5432/MY_DB作为 postgres url - 这里的“localhost”地址是正确的吗?

I verified that the above postgres url works when I try (no password):我验证了上述 postgres url 在我尝试时有效(无密码):

> psql postgres://USER:@localhost:5432/my_db
psql (12.2)
Type "help" for help.

> my_db=#

How else can I troubleshoot it?我还能如何解决它? The logs aren't very helpful...日志不是很有帮助...

If I got you correctly, the issue is that the Pod (from "inside" the Minikube ) can not access Postgres installed on Host machine (the one that runs Minikube itself) via localhost .如果我理解正确,问题是 Pod(从 Minikube “内部”)无法通过localhost访问安装在主机(运行 Minikube 的机器)上的 Postgres。

If that is the case, please check this thread .如果是这种情况,请检查此线程

... Minikube VM can access your host machine's localhost on 192.168.99.1 (127.0.0.1 from Minikube would still be a Minicube's localhost). ... Minikube VM 可以在 192.168.99.1 上访问主机的 localhost(来自 Minikube 的 127.0.0.1 仍然是 Minicube 的 localhost)。

Technically, for the Pod the localhost is Pod itself.从技术上讲,对于 Pod, localhost就是 Pod 本身。 The Host machine and Minikube are connected via bridge. Host 机器和 Minikube 通过网桥连接。 You can find out exact ip addresses and routes with the infconfig and route -n on your Minikube Host.您可以在 Minikube 主机上使用infconfigroute -n找到确切的 ip 地址和路由。

sorry to write it here, but I have the same issue.很抱歉在这里写,但我有同样的问题。 Could you fix it and share with me the solution?你能修复它并与我分享解决方案吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM