DNS resolution from kubernetes host

6/30/2020

kubernetes has DNS resolution for service or pod. For example, if I log into a pod, I can access the services or pods via DNS name, like mysvc.default.svc.

But how can I access them by DNS directly from Kubernetes host?

Currently, I have to get the IP address in order to access the service, which is inconvenient.

Thanks!

-- Wei Huang
kubernetes

2 Answers

6/30/2020

You can not use kubernetes cluster DNS (CoreDNS) from outside kubernetes i.e from the host machine. You should expose the pod via ingress or loadbalancer or NodePort type service and configure an external DNS provider to resolve a hostname to the IP.

-- Arghya Sadhu
Source: StackOverflow

6/30/2020

You not be able use CoreDNS from outside kubernetes. You should expose the pod via Ingress or LoadBalancer or NodePort Type service and configure an external DNS provider to resolve a hostname to the IP as Arghya Sadhu answers.

Other approach use external IP to your services and communicate with your Public IP directly.

Here some example : 1. External IP

apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: ClusterIP
  ports:
   - port: 5432
     targetPort: 5432
  selector:
   app: postgres
  externalIPs:
    - <YOUR_PUBLIC_IP_ADDRESS>
  1. NodePort
apiVersion: v1
kind: Service
metadata:
  name: postgres
  labels:
    app: postgres
spec:
  type: NodePort
  ports:
   - port: 5432
     targetPort: 5432
  selector:
   app: postgres
-- Bayu Dwiyan Satria
Source: StackOverflow