K8s/Kubernetes CoreDNS - add additional SRV or A records (manually)

8/12/2020

I do have the requirement to setup SRV entries for specific application.

I am running a kubernetes cluster with coredns and kubernetes plugin enabled. By standard the coredns is creating an SRV entry in the coredns database.

SRV record

K8s service

apiVersion: v1
kind: Service
metadata:
  labels:
    run: pod-nginx
  name: svc-nginx
  namespace: default
spec:
  ports:
  - name: test
    nodePort: 31985
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: pod-nginx
  type: LoadBalancer

Name resolution

I am able to get an answer from DNS query.

root@test:/# dig -t srv _test._tcp.svc-nginx.default.svc.cluster.local

; <<>> DiG 9.16.1-Ubuntu <<>> -t srv _test._tcp.svc-nginx.default.svc.cluster.local
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28386
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 2
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 66150d8a64d0f92b (echoed)
;; QUESTION SECTION:
;_test._tcp.svc-nginx.default.svc.cluster.local.	IN SRV

;; ANSWER SECTION:
_test._tcp.svc-nginx.default.svc.cluster.local.	5 IN SRV 0 100 80 svc-nginx.default.svc.cluster.local.

;; ADDITIONAL SECTION:
svc-nginx.default.svc.cluster.local. 5 IN A	192.168.200.88

;; Query time: 4 msec
;; SERVER: 192.168.200.2#53(192.168.200.2)
;; WHEN: Wed Aug 12 07:23:48 UTC 2020
;; MSG SIZE  rcvd: 239

Unfortunatelly I do need another SRV string, as the application is expecting a different SRV resolution. I am not able to edit the application to fit the automatically created SRV string.

How can I manually add SRV entires into coreDNS?

current SRV record:

_test._tcp.svc-nginx.default.svc.cluster.local.	5 IN SRV 0 100 80 svc-nginx.default.svc.cluster.local.

expected SRV record:

_test._tcp.default.svc.cluster.local.	86400 IN SRV 0 0 80 svc-nginx.default.svc.cluster.local.

A record

How can I manually add A records into coreDNS? I don't want to use the "rewrite plugin" or the "k8s_external plugin"

current A record:

svc-nginx.default.svc.cluster.local. 5 IN A	192.168.200.88

expected SRV record:

myapp.cluster.local. 5 IN A	192.168.200.88
-- chuet
coredns
dns
kubernetes

0 Answers