Unable to resolve Kubernetes service names inside containers with the hostNetwork

Viewed 85

Unable to use Kubernetes internal DNS when hostNetwork is used:

/ test# nslookup echo
Server:    10.96.0.10
Address 1: 10.96.0.10

nslookup: can't resolve 'echo'

Without hostNetwork:

/ test# nslookup echo
Server:    10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name:      echo
Address 1: 10.98.232.198 echo.default.svc.cluster.local

Kubernetes 1.18.5 on bare-metal not upgraded (fresh install).

Full config:

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: test
  labels:
    app: test

spec:
  selector:
    matchLabels:
      app: test

  template:
    metadata:
      labels:
        app: test

    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet

      containers:
      - image: busybox:1.28
        command:
          - sleep
          - "3600"
        imagePullPolicy: IfNotPresent
        name: busybox

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: echo
  template:
    metadata:
      labels:
        app: echo
    spec:
      containers:
        - name: echo
          image: jmalloc/echo-server
          ports:
            - name: http-port
              containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: echo
spec:
  ports:
    - name: http-port
      port: 80
      targetPort: http-port
      protocol: TCP
  selector:
    app: echo
1 Answers

A fresh install of Kubernetes 1.19.0 solved this problem.

Related