Kubernetes ExternalName service does not resolve

4/26/2018

If created a service using an externalName pointing to some external service.

apiVersion: v1
kind: Service
metadata:
  name: test
spec:
  type: ExternalName
  externalName: google.com

When I now try to do a DNS lookup it doesn't return anything useful:

# dig test.development.svc.cluster.local.

; <<>> DiG 9.9.5-9+deb8u15-Debian <<>> test.development.svc.cluster.local.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58159
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;test.development.svc.cluster.local. IN A

;; AUTHORITY SECTION:
cluster.local.      60  IN  SOA ns.dns.cluster.local. hostmaster.cluster.local. 1524736800 28800 7200 604800 60

;; Query time: 0 msec
;; SERVER: 100.64.0.10#53(100.64.0.10)
;; WHEN: Thu Apr 26 10:58:48 UTC 2018
;; MSG SIZE  rcvd: 106

If I query explicitly for type CNAME I get a response:

# dig -t CNAME test.development.svc.cluster.local.

; <<>> DiG 9.9.5-9+deb8u15-Debian <<>> -t CNAME test.development.svc.cluster.local.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54517
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test.development.svc.cluster.local. IN CNAME

;; ANSWER SECTION:
test.development.svc.cluster.local. 30 IN CNAME google.com.

;; Query time: 0 msec
;; SERVER: 100.64.0.10#53(100.64.0.10)
;; WHEN: Thu Apr 26 10:59:55 UTC 2018
;; MSG SIZE  rcvd: 76

If I change the Service to point to some other cluster internal service, I get the following expected result of an IP address:

# dig dogstatsdport.development.svc.cluster.local

; <<>> DiG 9.9.5-9+deb8u15-Debian <<>> dogstatsdport.development.svc.cluster.local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32857
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;dogstatsdport.development.svc.cluster.local. IN    A

;; ANSWER SECTION:
dogstatsdport.development.svc.cluster.local. 30 IN CNAME dogstatsdport.default.svc.cluster.local.
dogstatsdport.default.svc.cluster.local. 30 IN A 100.68.195.103

;; Query time: 0 msec
;; SERVER: 100.64.0.10#53(100.64.0.10)
;; WHEN: Thu Apr 26 11:02:14 UTC 2018
;; MSG SIZE  rcvd: 113

What is missing/wrong here? And how do I get the external record to resolve?

Cluster is currently running on Kubernetes 1.8.12, set up with kops 1.9.0.

-- Jonathan
kubernetes

1 Answer

4/26/2018

The issue lies with the used kube-dns version 1.14.9.

Applying the following command to update to 1.14.10 fixed it:

kubectl set image deployment/kube-dns -n kube-system \
  kubedns=gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.10 \
  dnsmasq=gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.10 \
  sidecar=gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.10

https://github.com/kubernetes/dns/releases states for 1.14.10:

Merge pull request #225 from grayluck/externalname Fix external name not solving by reloading resolv.conf.

-- Jonathan
Source: StackOverflow