首页 > 解决方案 > 使用 kubernetes 集群作为一种路由器从 Tableau 访问 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

标签: postgresqlkubernetestableau-api

解决方案


您可以通过创建没有选择器的服务类型对象然后手动为其创建端点来实现这一点。服务需要通过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

服务不直接链接到 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


推荐阅读