Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Docker 如何让kubernetes pod访问PostgreSQL pod_Docker_Kubernetes_Kubernetes Helm_Kubectl - Fatal编程技术网

Docker 如何让kubernetes pod访问PostgreSQL pod

Docker 如何让kubernetes pod访问PostgreSQL pod,docker,kubernetes,kubernetes-helm,kubectl,Docker,Kubernetes,Kubernetes Helm,Kubectl,我正在尝试本地Kubernetes(mac上的Docker),并尝试提交一份spark作业。spark作业,连接PostgreSQL数据库并进行一些计算 PostgreSQL正在我的Kube上运行,因为我已经发布了它,所以我可以通过localhost:5432从主机访问它。但是,当spark应用程序试图连接到PostgreSQL时,它会抛出 Exception in thread "main" org.postgresql.util.PSQLException: Connection to lo

我正在尝试本地Kubernetes(mac上的Docker),并尝试提交一份spark作业。spark作业,连接PostgreSQL数据库并进行一些计算

PostgreSQL正在我的Kube上运行,因为我已经发布了它,所以我可以通过localhost:5432从主机访问它。但是,当spark应用程序试图连接到PostgreSQL时,它会抛出

Exception in thread "main" org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
kubectl集群信息

Kubernetes master is running at https://kubernetes.docker.internal:6443
KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

kubectl获得发布的postgresql服务

kubectl描述服务spark-store-1588217023181-driver-svc

Name:              spark-store-1588217023181-driver-svc
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          spark-app-selector=spark-533ecb8556b6439eb938d487cc77c330,spark-role=driver
Type:              ClusterIP
IP:                None
Port:              driver-rpc-port  7078/TCP
TargetPort:        7078/TCP
Endpoints:         <none>
Port:              blockmanager  7079/TCP
TargetPort:        7079/TCP
Endpoints:         <none>
Session Affinity:  None
名称:spark-store-1588217023181-driver-svc
名称空间:默认值
标签:
注释:
选择器:spark应用程序选择器=spark-533ecb8556b6439eb938d487cc77c330,spark角色=驾驶员
类型:集群
IP:没有
端口:驱动程序rpc端口7078/TCP
目标端口:7078/TCP
端点:
端口:blockmanager 7079/TCP
目标端口:7079/TCP
端点:
会话关联:无

我如何进行spark工作,访问PostgreSQL服务?

localhost
EXTERNAL\u IP
中有,但Kubernetes群集DNS系统(CoreDNS)中没有不知道如何将其解析为IP地址。
EXTERNAL_IP
应该由外部DNS服务器解析,通常用于从Kubernetes群集外部(即从另一个系统或Kubernetes节点)而不是从群集内部(即从另一个pod)连接到Postgres

Postgres应该可以从spark pod通过
10.106.15.112:5432
postgresql发布:5432
访问,因为kubernetes群集DNS系统知道如何解决它

测试Postgres的连通性

kubectl run postgresql-postgresql-client --rm --tty -i --restart='Never' --namespace default --image bitnami/postgresql --env="PGPASSWORD=<HERE_YOUR_PASSWORD>" --command -- psql --host <HERE_HOSTNAME=SVC_OR_IP> -U <HERE_USERNAME> 
kubectl运行postgresql-postgresql客户端--rm--tty-i--restart='Never'--namespace默认--image-bitnami/postgresql--env=“PGPASSWORD=”--command--psql--host-U

localhost
存在于
EXTERNAL_-IP
中,但Kubernetes群集DNS系统(CoreDNS)不知道如何将其解析为IP地址。
EXTERNAL_-IP
应该由外部DNS服务器解析,通常用于从Kubernetes群集外部连接到Postgres(即来自另一个系统或Kubernetes节点)而不是来自集群内部(即来自另一个pod)

Postgres应该可以从spark pod通过
10.106.15.112:5432
postgresql发布:5432
访问,因为kubernetes群集DNS系统知道如何解决它

测试Postgres的连通性

kubectl run postgresql-postgresql-client --rm --tty -i --restart='Never' --namespace default --image bitnami/postgresql --env="PGPASSWORD=<HERE_YOUR_PASSWORD>" --command -- psql --host <HERE_HOSTNAME=SVC_OR_IP> -U <HERE_USERNAME> 
kubectl运行postgresql-postgresql客户端--rm--tty-i--restart='Never'--namespace默认--image-bitnami/postgresql--env=“PGPASSWORD=”--command--psql--host-U
表示该服务应可在集群内访问,地址为
10.106.15.112:5432
postgresql发布日期:5432
,外部地址为
localhost:31277

请注意,对于Pod而言,
localhost
就是Pod本身。在这种情况下,
localhost
看起来模棱两可。然而,这就是Pod的工作原理

表示该服务应可在集群内访问,地址为
10.106.15.112:5432
postgresql发布日期:5432
,外部地址为
localhost:31277


请注意,对于Pod而言,
localhost
就是Pod本身。在这种情况下,
localhost
看起来模棱两可。不过,这就是工作原理。

感谢您的帮助!!PostgreSQL有一个外部ip,我可以通过终端连接它。但是,当我提交spark作业时,作业无法与其他人合作连接到数据库。你能从pod通过10.106.15.112:5432访问它吗?使用10.106.15.112:5432确实有效。请帮助我理解为什么它不能与LocalHosteExternal_一起工作。IP只能从外部解析。postgresql发布:5432应该可以从spark pod工作谢谢你的帮助!!postgresql有一个外部IP,我可以通过我的终端连接。但是,当我提交spark作业时,该作业无法连接到数据库。您可以通过pod通过10.106.15.112:5432访问它吗?使用10.106.15.112:5432确实有效。请帮助我理解为什么它不能与localhostEXTERNAL_IP一起工作,这只能从外部解决。postgresql已发布:5432应从spark Pod开始工作,尝试以
postgresql发布的身份连接postgres主机,因为这是您的服务。尝试以
postgresql发布的身份连接postgres主机,因为这是您的服务。