Skip to content

Commit a25ccfc

Browse files
committed
get node-local-dns pod ip
1 parent 963b914 commit a25ccfc

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

config/local-dns-resolver-config.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@
1919
"type": "permanent",
2020
"condition": "NodeLocalDnsResolutionFailure",
2121
"reason": "NodeLocalDnsResolutionFailing",
22-
"path": "./config/plugin/local_dns_resolver.sh",
23-
"args": [
24-
"169.254.20.10"
25-
]
22+
"path": "./config/plugin/local_dns_resolver.sh"
2623
}
2724
]
2825
}

config/plugin/local_dns_resolver.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ OK=0
44
NONOK=1
55
UNKNOWN=2
66

7-
readonly local_dns_resolver_ip="$1"
7+
if [ -z "${NODE_NAME}" ]; then
8+
exit $UNKNOWN
9+
fi
10+
11+
# Get the node-local-dns pod IP running on this node directly,
12+
# bypassing 169.254.20.10 which requires Cilium's eBPF path
13+
local_dns_resolver_ip="$(curl -s \
14+
-H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" \
15+
--cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt \
16+
"https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/namespaces/kube-system/pods?labelSelector=k8s-app%3Dnode-local-dns&fieldSelector=spec.nodeName%3D${NODE_NAME}" \
17+
2>/dev/null | jq -r '.items[0].status.podIP')"
18+
19+
if [ -z "${local_dns_resolver_ip}" ] || [ "${local_dns_resolver_ip}" = "null" ]; then
20+
exit $UNKNOWN
21+
fi
822

923
dig_cmd_out="$(dig -t TXT @"${local_dns_resolver_ip}" +tries=1 +retry=0 +time=33 +noqr +noall +comments kubernetes.default.svc. 2>&1)"
1024
dig_cmd_return_code="$?"

0 commit comments

Comments
 (0)