使用 kubernetes 集群作为一种路由器从 Tableau 访问 Postgres 主机

Access Postgres host from Tableau using kubernetes cluster as a kind of router

场景:

我需要什么:

重要限制:


后续步骤 现在我可以使用 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

您可以通过创建不带选择器的服务类型对象然后手动为其创建端点来实现此目的。服务需要通过 NodePortLoadbalancer 类型暴露在外:

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