如何在Google Kubernetes中访问Postgresql Pod/Service [英] How to access postgresql pod/service in google kubernetes

查看:136
本文介绍了如何在Google Kubernetes中访问Postgresql Pod/Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署一个简单的Web应用程序.我将其分为3个Pod:前端,后端和postgres db.我已成功将前端和后端部署到google kubernetes服务,并且它们按预期工作.但是对于我的postgresql数据库服务器,我使用了以下yamls.我使用来自dockerhub的标准postgres图像创建了postgres图像.我创建了一些表,并插入了一些数据并将其推送到DockerHub.我的后端无法建立与我的数据库的连接.我想可能需要更改我的Java连接代码.不确定使用localhost.它在我的本地Eclipse Jee和Tomcat上没有任何问题.

I am deploying a simple web application. I divided it into 3 pods:front end, back end, and postgres db. I successfully deployed my front end and back end to google kubernetes service and they works as expected. But for my postgresql db server, I used the following yamls. The postgres image is created by me using standard postgres images from dockerhub. I created some tables, and inserted some data and pushed to DockerHub. My backend is not able to make connection to my db. I think I might need to change my Java connection code.Not sure on using localhost. It works without any issue on my local Eclipse Jee and Tomcat.

//my pod.yaml
apiVersion: v1
kind: Pod
metadata:
   name: postgres-app-pod
   labels:
      name: postgres-app-pod
      app: demo-geo-app
spec:
   containers:
   - name: postgres
     image: myrepo/example:v1
     ports:
     - containerPort: 5432

//my service.yaml
apiVersion: v1
kind: Service
metadata:
   name: db
   labels:
      name: db-service
      app: demo-geo-app
spec:
   ports:
   - port: 5432
     targetPort: 5432
   selector:
      name: postgres-pod
      app: demo-geo-app 

   //from my java backend, I access my db server this way.
String dbURL = "jdbc:postgresql://localhost:5432/Location?user=postgres&password=mysecretpassword";

推荐答案

有两个问题需要解决.

  1. 服务选择器键:值应与吊舱标签匹配
  2. 用PostgreSQL服务dns替换本地主机

这篇关于如何在Google Kubernetes中访问Postgresql Pod/Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆