2
k3s: enable DNS resolution from host to k3s services
Andy edited this page 2023-01-24 13:53:14 +00:00
The following enables DNS resolution from host to k3s services for default.svc.cluster.local
& svc.cluster.local
domains:
sudo mkdir -p /etc/systemd/resolved.conf.d
cat <<EOF | sudo tee /etc/systemd/resolved.conf.d/k3s-kube-dns.conf
[Resolve]
DNS=$(kubectl -n kube-system get ep kube-dns -o jsonpath='{.subsets[0].addresses[0].ip}')
FallbackDNS=
Domains=default.svc.cluster.local svc.cluster.local
DNSSEC=no
Cache=no-negative
EOF
sudo systemctl restart systemd-resolved
Verification:
$ resolvectl
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: stub
Current DNS Server: 10.42.0.2
DNS Servers: 10.42.0.2
DNS Domain: default.svc.cluster.local svc.cluster.local
...
$ host kube-dns.kube-system.svc.cluster.local
kube-dns.kube-system.svc.cluster.local has address 10.43.0.10
$ nc -vz kube-dns.kube-system.svc.cluster.local 53
Connection to kube-dns.kube-system.svc.cluster.local (10.43.0.10) 53 port [tcp/domain] succeeded!