postgresql - 使用 kubernetes 集群作为一种路由器从 Tableau 访问 Postgres 主机
问题描述
设想:
表格应用程序;
云上的 Postgres;
Kubernetes 在另一个云上,运行一个基于 Alpine 镜像的应用程序(不同于 Postgres 的云)。
我需要什么:
- 使用 Kubernetes 作为一种路由器从 Tableau 访问 Postgres;所以我需要从 tableau 向我的 Kubernetes 集群发送请求,并且我的 Kubernetes 集群需要将申请重定向到我的 Postgres 主机,并且 Postgres 必须回复我的 kubernetes 集群,之后我的 Kubernetes 集群必须从 Postgres 发送 de answer到 Tableau。
重要限制:
Tableau 可以访问我的 kubernetes 集群,但不能直接访问我的 Postgres 主机;
我的 kubernetes 集群可以访问我的 Postgres 主机。
后续步骤 现在我可以使用 Thomas answer 使用以下代码使其工作:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: NodePort
ports:
- port: 5432
targetPort: 5432
nodePort: 30004
---
apiVersion: v1
kind: Endpoints
metadata:
name: my-service
subsets:
- addresses:
- ip: **111.111.111.111** ** < need change this to hostname
ports:
- port: 5432
数字 IP 一切正常,但我需要使用我的 Postgres DNS,例如:
subsets:
- addresses:
- ip: mypostgres.com
ports:
- port: 5432
解决方案
您可以通过创建没有选择器的服务类型对象然后手动为其创建端点来实现这一点。服务需要通过NodePort
或Loadbalancer
输入外部暴露:
apiVersion: v1
kind: Service
metadata:
name: my-service #Name of the service must match the name of the endpoints
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30007
服务不直接链接到 pod。在称为端点之间还有另一个对象。因此,您可以手动定义它们。
apiVersion: v1
kind: Endpoints
metadata:
name: my-service #Name of te endpoint must match the name of the service
subsets:
- addresses:
- ip: 172.217.212.100 # This is the IP of the endpoints that the service will forward connections to.
ports:
- port: 80
由于您要公开您的 postgres,因此必须采取某种安全措施来保护它,例如白名单 ip
更多阅读请访问/Services without selectors。
推荐阅读
- sql-server - 将两个字符串连接为一个而不重复
- python - 使用 ping 确定远程机器的操作系统
- ios - 如何在导航栏中设置两种颜色?
- json - 由于 JSON::ParserError 随机失败:822:意外令牌
- jquery - Safari 不加载一张图片
- c# - 无法在 C# 中读取 PDF 控件
- c# - System.Net.Mail.Attachment 文件 url 包含 #
- android - 在 Google 日历中为“一天两次”、“一天三次”等重复事件创建提醒时出现问题
- android - 为什么在我删除由 Create New Project 向导创建的代码 setSupportActionBar(toolbar) 后,选项卡式 Activity 运行良好?
- objective-c - 10.9 中的 NSScrollView 辅助功能问题