使用 kubernetes 集群作为一种路由器从 Tableau 访问 Postgres 主机
Access Postgres host from Tableau using kubernetes cluster as a kind of router
场景:
Tableau 应用程序;
云上的 Postgres;
另一个云上的 Kubernetes,运行 基于 Alpine 镜像的应用程序(与 Postgres 不同的云)。
我需要什么:
- 使用 Kubernetes 作为一种路由器从 Tableau 访问 Postgres;
所以我需要从 tableau 向我的 Kubernetes 集群发送请求,我的 Kubernetes 集群需要将请求重定向到我的 Postgres 主机,并且 Postgres 必须在我的 Kubernetes 集群必须从 Postgres 发送回复之后回复我的 kubernetes 集群到 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
服务不会直接 link 到 pods。在称为端点之间还有另一个对象。因此,您可以手动定义它们。
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,因此必须采取某种安全措施来保护它,例如whitelist ip
更多阅读请访问/Services without selectors。
场景:
Tableau 应用程序;
云上的 Postgres;
另一个云上的 Kubernetes,运行 基于 Alpine 镜像的应用程序(与 Postgres 不同的云)。
我需要什么:
- 使用 Kubernetes 作为一种路由器从 Tableau 访问 Postgres; 所以我需要从 tableau 向我的 Kubernetes 集群发送请求,我的 Kubernetes 集群需要将请求重定向到我的 Postgres 主机,并且 Postgres 必须在我的 Kubernetes 集群必须从 Postgres 发送回复之后回复我的 kubernetes 集群到 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
服务不会直接 link 到 pods。在称为端点之间还有另一个对象。因此,您可以手动定义它们。
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,因此必须采取某种安全措施来保护它,例如whitelist ip
更多阅读请访问/Services without selectors。