How do I use minikube's DNS? How do I use minikube's DNS? kubernetes kubernetes

How do I use minikube's DNS?


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 -- bashroot@dns:/# dig +search <service>

Let me know it it helped.


As illustrated in kubernetes/minikube issue 4397

Containers don't have an IP address by default.
You'll want to use minikube service or minikube tunnel to get endpoint information.

See "hello-minikube/ Create a service":

By default, the Pod is only accessible by its internal IP address within the Kubernetes cluster.

To make the hello-node Container accessible from outside the Kubernetes virtual network, you have to expose the Pod as a Kubernetes Service.

Expose the Pod to the public internet using the kubectl expose command:

kubectl expose deployment hello-node --type=LoadBalancer --port=8080

The --type=LoadBalancer flag indicates that you want to expose your Service outside of the cluster.

View the Service you just created:

kubectl get servicesNAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGEhello-node   LoadBalancer   10.108.144.78   <pending>     8080:30369/TCP   21skubernetes   ClusterIP      10.96.0.1       <none>        443/TCP      

On Minikube, the LoadBalancer type makes the Service accessible through the minikube service command.

Run the following command:

minikube service hello-node