Gokul Kulanthaivel
Gokul Kulanthaivel

Reputation: 121

Kubernetes Pod cannot communicate with external services like Oracle, Mongo etc

My database is running in different host which is not deployed in kubernetes( for eg: hostName is testDevDb)

When i run my Micro Service(MS) as K8 Pod, MS cannot able to open connection with external database. i am getting unknown host exception. Looks like DNS is not resolved.

Caused by: java.net.UnknownHostException: testDevDb
    at java.net.InetAddress$CachedAddresses.get(InetAddress.java:797) ~[?:?]
    at java.net.InetAddress.getAllByName0(InetAddress.java:1505) ~[?:?]
    at java.net.InetAddress.getAllByName(InetAddress.java:1364) ~[?:?]
    at java.net.InetAddress.getAllByName(InetAddress.java:1298) ~[?:?]

I don't find right article to resolve this.

Is there any way to use of host's /etc/resolv.conf inside K8's POD.

Please help me the right approach to resolve this

Upvotes: 4

Views: 341

Answers (1)

Furkan
Furkan

Reputation: 171

If you want to add host and IP information to /etc/hosts file inside a pod, you can use hostAliases. There is an example for a pod in doc.

sample deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: yourdeploymentname
  labels:
    app: yourapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: yourapp
  template:
    metadata:
      labels:
        app: yourapp
    spec:
      containers:
      - name: yourapp
        image: yourappimage:latest
    hostAliases:
      - ip: "10.10.10.10"
        hostnames:
        - "testDevDb"

Upvotes: 0

Related Questions