无法从客户端工具连接到Kubernetes minikube上的postgres sql



我已经成功地在Kubernetes上部署了postgres。

postgres                                 NodePort    10.96.66.202     <none>        5432:30030/TCP 

我可以使用localhost和5432通过以下命令连接到postgres:

kubectl exec -it postgres-75b8fd84f-gkj6k -- psql -h localhost -U appuser --password -p 5432 appdb

但是,当我尝试使用另一个客户端工具使用节点端口和minikube IP访问psql时,我得到了以下错误:

host=$(minikube ip)
192.168.49.2
port=$(kubectl get service postgres -o jsonpath='{.spec.ports[0].nodePort}')
30030
$ psql -h 10.96.66.202 -U appuser --password -p 30030 appdb
Password: 
psql: error: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "10.96.66.202" and accepting
TCP/IP connections on port 30030?

编辑:

我也尝试了minikube IP:

$ psql -h 192.168.49.2 -U appuser --password -p 30030 appdb
Password:
psql: error: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "192.168.49.2" and accepting
TCP/IP connections on port 30030?

我也尝试过这种组合:

$ psql -h 10.96.66.202 -U appuser --password -p 5432 appdb
Password:
psql: error: could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "10.96.66.202" and accepting
TCP/IP connections on port 5432?

IP192.168.49.2用于节点,10.96.66.202用于服务。

nodePort30030用于节点,targetPort5432用于服务。

所以你可以使用

psql -h 192.168.49.2 -U appuser --password -p 30030 appdb

psql -h 10.96.66.202 -U appuser --password -p 5432 appdb

最新更新