LuizBuffa
LuizBuffa

Reputation: 75

Kubernetes create an endpoint with DNS instead IP

I need to create an endpoint with DNS instead of IP

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 DNS
    ports:
      - port: 5432


Everything works fine with numerical IP, but I need to put my Postgres DNS instead, something like:

subsets:
  - addresses:
      - ip: mypostgres.com
    ports:
      - port: 5432

But "addresses" only support numerical IP. I need some workaround to make this work.

Upvotes: 3

Views: 5140

Answers (1)

Harsh Manvar
Harsh Manvar

Reputation: 30083

if you want to connect to a remotely hosted database URI instead of IP you can use ExternalName

kind: Service
apiVersion: v1
metadata:
 name: mongo
spec:
 type: ExternalName
 externalName: ds149763.mlab.com

Please check out more : https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-mapping-external-services

Upvotes: 0

Related Questions