https://kubernetes.io/docs/tasks/administer-cluster/nodelocaldns/
to retrieve hostIP from pod add env to daemonset - dig kubernetes-node
- will return hostIP of current pod
env:
- name: POD_HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
rewrite continue {
ttl regex .* 30
}
# ec2 fix
rewrite stop name regex ^(ip-\d{1,3}-\d{1,3}-\d{1,3}-\d{1,3}\.ec2\.internal) {1}
rewrite stop name regex .*\.ec2\.internal ec2.internal.invalid
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
upstream
fallthrough in-addr.arpa ip6.arpa
ttl 30
}
prometheus :9153
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
apiVersion: v1
kind: ConfigMap
metadata:
name: node-local-dns
namespace: kube-system
data:
Corefile: |
cluster.local:53 {
errors
cache 30
reload
loop
bind 169.254.20.10
forward . 10.100.0.10 {
force_tcp
}
prometheus :9253
health 169.254.20.10:8080
}
in-addr.arpa:53 {
errors
cache 30
reload
loop
bind 169.254.20.10
forward . 10.100.0.10 {
force_tcp
}
prometheus :9253
}
ip6.arpa:53 {
errors
cache 30
reload
loop
bind 169.254.20.10
forward . 10.100.0.10 {
force_tcp
}
prometheus :9253
}
ec2.internal:53 {
errors
cache 30
reload
loop
bind 169.254.20.10
forward . 10.100.0.10 {
force_tcp
}
prometheus :9253
}
.:53 {
errors
cache 30
reload
loop
bind 169.254.20.10
template IN A kubernetes-node {
answer "{{ .Name }} 30 IN A {$POD_HOST_IP}"
}
forward . 10.100.0.10 {
force_tcp
}
prometheus :9253
}