What IP Address should I point to in my containerized Python application that is deployed on a Kubernetes cluster?

1/31/2020

So I currently have a database server that is up and running. I have it running on 0.0.0.0:8080. I have another python file making requests to that IP address, but when I run it in a container I have this python file point to the container's IP address, but when I have it on a kubernetes cluster I have it now point to the IP address of the kubernetes pod.

The pod IP address constantly changes, so how do I solve this approach?

-- John Cena
docker
kubernetes
python

1 Answer

1/31/2020

Define a Service for that database:

https://kubernetes.io/docs/concepts/services-networking/service/

This will expose the database with a fixed DNS name. Then from your python app, use the service name to access your database. The service will direct the traffic to the correct IP.

-- Burak Serdar
Source: StackOverflow