Kubernetes: Automatically determine IP Address of another pod/container Kubernetes: Automatically determine IP Address of another pod/container flask flask

Kubernetes: Automatically determine IP Address of another pod/container


As long as you have the kube-dns add-on enabled in minikube you should be able to perform DNS-based service discovery. I would say that this is the recommended way of getting hold of the IP addresses of your resources.

To double check that you have kube-dns enabled run minikube addons list, it should be enabled by default.

The DNS names created for you will default be derived from the metadata: name field of your resource(s). Assuming you'll be using the default namespace then your Services DNS-names would be:

interceptor-service.default.svc.cluster.local

and

frontend-service.default.svc.cluster.local

You could use these fully qualified domain-names within your application to reach your Services or use a shorter version e.g. frontend-service as-is. This is possible since your Pods resolv.conf will be configured to look in default.svc.cluster.local when querying for frontend-service.

To test this (and noted in the comments), you should now be able to change this line:

address = 'http://172.17.0.5:5002/'

to

address = 'http://interceptor-service:5002/'

in your Flask app code.

Please see this page for more detailed information about DNS for Services and Pods in Kubernetes.