Skip to content

Instantly share code, notes, and snippets.

@rbo
Last active January 8, 2021 13:05
Show Gist options
  • Save rbo/ee20b356477d26e30826585da9b5b1ed to your computer and use it in GitHub Desktop.
Save rbo/ee20b356477d26e30826585da9b5b1ed to your computer and use it in GitHub Desktop.
Check connection to openshift coredns endpoints
# How to deploy:
# oc new-project dns-checker
# oc adm policy add-cluster-role-to-user cluster-reader -z default
# oc apply -f ...
# Example logout:
# # Collected DNS Endpoints: 10.129.0.40 10.129.2.5 10.130.0.13 10.130.2.3 10.131.0.7 10.131.2.3
# # Run on Node: compute-1.ocp3.stormshift.coe.muc.redhat.com
# # Fri Jan 8 13:04:32 UTC 2021
# DNS IP: 10.129.0.40 : PASS (Details: 172.30.0.1 from server 10.129.0.40 in 0 ms. )
# DNS IP: 10.129.2.5 : PASS (Details: 172.30.0.1 from server 10.129.2.5 in 0 ms. )
# DNS IP: 10.130.0.13 : PASS (Details: 172.30.0.1 from server 10.130.0.13 in 3 ms. )
# DNS IP: 10.130.2.3 : PASS (Details: 172.30.0.1 from server 10.130.2.3 in 1 ms. )
# DNS IP: 10.131.0.7 : PASS (Details: 172.30.0.1 from server 10.131.0.7 in 0 ms. )
# DNS IP: 10.131.2.3 : PASS (Details: 172.30.0.1 from server 10.131.2.3 in 0 ms. )
apiVersion: apps/v1
kind: DaemonSet
metadata:
creationTimestamp: null
labels:
run: dns-checker
name: dns-checker
spec:
updateStrategy:
type: OnDelete
selector:
matchLabels:
run: dns-checker
template:
metadata:
creationTimestamp: null
labels:
run: dns-checker
spec:
tolerations:
- operator: Exists
containers:
- image: quay.io/openshift-examples/toolbox:main
imagePullPolicy: Always
name: dns-checker
command:
- /bin/bash
- -c
- |
#!/bin/bash
while true; do
DNS_ENDPOINTS=$( curl --silent \
--cacert /run/secrets/kubernetes.io/serviceaccount/ca.crt \
--header "Authorization: Bearer $(cat /run/secrets/kubernetes.io/serviceaccount/token)" \
https://kubernetes.default.svc.cluster.local/api/v1/namespaces/openshift-dns/endpoints/dns-default | jq '.subsets[] | .addresses[] | .ip' -r | tr "\n " " ")
echo "# Collected DNS Endpoints: $DNS_ENDPOINTS"
echo "# Run on Node: $K8S_NODENAME"
echo -n "# ";date
for i in $DNS_ENDPOINTS ; do
printf "DNS IP: %-16s : " $i
RESULT=$(dig -p 5353 +retry=1 +tries=1 +time=1 +short +identify kubernetes.default.svc.cluster.local. @${i})
RC=$?
if [ $RC -gt 0 ] ; then
echo -n "FAIL (RC: $RC)"
else
echo -n "PASS"
fi
echo -n " (Details: $RESULT )"
echo ""
done
sleep 5;
done;
env:
- name: K8S_NODENAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment