Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use minikube's DNS?

How do I use minikube's (cluster's) DNS? I want to receive all IP addresses associated with all pods for selected headless service? I don’t want to expose it outside the cluster. I am currently creating back-end layer.

As stated in the following answer: What exactly is a headless service, what does it do/accomplish, and what are some legitimate use cases for it?

„Instead of returning a single DNS A record, the DNS server will return multiple A records for the service, each pointing to the IP of an individual pod backing the service at that moment.”

Thus the pods in back-end layer can communicate to each other.

I can’t use dig command. It is not installed in minikube. Eventually how do I install it? There is no apt available.

I hope this explains more accurately what I want to achieve.

like image 601
hal Avatar asked Nov 21 '19 17:11

hal


People also ask

How do you check if DNS is working Kubernetes?

Use the kubectl get pods command to verify that the DNS pod is running.

How does Kubernetes DNS work?

Kubernetes DNS schedules a DNS Pod and Service on the cluster, and configures the kubelets to tell individual containers to use the DNS Service's IP to resolve DNS names. Every Service defined in the cluster (including the DNS server itself) is assigned a DNS name.

How do I find the DNS name for my pod?

Debugging DNS Alternatively, you can check if the kubedns/coredns pods are running: kubectl get pods --namespace=kube-systemNAME READY STATUS RESTARTS AGE....


1 Answers

You mentioned that you want to receive IP addresses associated with pods for selected service name for testing how does headless service work.

For only testing purposes you can use port-forwarding. You can forward traffic from your local machine to dns pod in your cluster. To do this, you need to run:

kubectl port-forward svc/kube-dns -n kube-system 5353:53

and it will expose kubs-dns service on your host. Then all you need is to use dig command (or alternative) to query the dns server.

dig @127.0.0.1 -p 5353 +tcp +short <service>.<namespace>.svc.cluster.local

You can also test your dns from inside of cluster e.g. by running a pod with interactive shell:

kubectl run --image tutum/dnsutils dns -it --rm -- bash
root@dns:/# dig +search <service>

Let me know it it helped.

like image 195
Matt Avatar answered Oct 04 '22 04:10

Matt