Skip to content

Instantly share code, notes, and snippets.

@dcasati
Last active November 3, 2023 02:28
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcasati/52f35d19ab5f8fcf355a36e0a1ee5e6a to your computer and use it in GitHub Desktop.
Save dcasati/52f35d19ab5f8fcf355a36e0a1ee5e6a to your computer and use it in GitHub Desktop.
kubernetes - Kube-DNS port forwarding and DNS querying.
# Use dig to find out about the k8s records
# dig +vc -p 5300 @127.0.0.1 cluser.local
# Use dig to retrieve an A Record
# dig +vc -p 5300 @127.0.0.1 A cb-example-0000.default.svc.cluster.local
# Use dig to do a reverse lookup (-x flag)
#dig +vc -p 5300 @127.0.0.1 -x 10.0.50.156
# Add the port forward
kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o template --template="{{range.items}}{{.metadata.name}}%{{end}}" | xargs -d % -L 1 -I{} kubectl port-forward --namespace=kube-system {} 5300:53
@kevinmingtarja
Copy link

Thanks a lot for this. Was trying to expose my k8s cluster's dns to my local and this worked perfectly!

@finalcreator
Copy link

Amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment