postgresql - Kubernetes Pod 无法使用 Hasura 映像连接到本地 postgres 服务器
问题描述
我正在按照本教程将 hasura kubernetes pod 连接到我的本地 postgres 服务器。
当我创建部署时,pod 的容器无法连接到 postgres(CrashLoopBackOff 并不断重试),但没有给出任何原因。以下是日志:
{"type":"pg-client","timestamp":"2020-05-03T06:22:21.648+0000","level":"warn","detail":{"message":"postgres connection failed, retrying(0)."}}
我的部署.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: {}
我postgres://USER:@localhost:5432/MY_DB
用作 postgres url - 这里的“localhost”是正确的地址吗?
当我尝试(无密码)时,我验证了上面的 postgres url 有效:
> psql postgres://USER:@localhost:5432/my_db
psql (12.2)
Type "help" for help.
> my_db=#
我还能如何解决它?日志不是很有帮助...
解决方案
如果我理解正确,问题是 Pod(从 Minikube“内部”)无法通过localhost
.
如果是这种情况,请检查此线程。
... Minikube VM 可以在 192.168.99.1 上访问主机的 localhost(来自 Minikube 的 127.0.0.1 仍然是 Minicube 的 localhost)。
从技术上讲,对于 Pod 来说,localhost
就是 Pod 本身。Host 机器和 Minikube 通过网桥连接。您可以使用Minikube 主机上的infconfig
和找到确切的 IP 地址和路由。route -n
推荐阅读
- f# - 我可以避免在 F# 中进行这种强制转换吗?
- java - 如果值包含“#”,则 Spring REST @RequestMapping 提取不正确
- javascript - 使用 Jinja 动态更新 Javascript 变量?
- java - OCPJP 8 什么是使用 NIO2 的符号链接
- php - SQLSTATE [42000]:语法错误或访问冲突:1064 IONIC
- php - PHPMailer 语法错误 全新安装
- reactjs - Redux-form 重置/删除 syncErrors
- node.js - 我需要尝试...捕获请求吗?
- spring-boot - 如何在多战 Tomcat 上共享 Hazelcast 缓存
- c++ - SFINAE 的不同 g++ 和 clang 行为