We are trying to implement two pods one with mondodba dn another one with java application. And java application requires to be bind with mongodb. How we can bind db and app when they are running on two different pods and with different subnets.
You may want to use service for your mongo
pod. You need to add label e.g. name: mongo
to pod and create a service:
apiVersion: v1
kind: Service
metadata:
name: mongo
spec:
ports:
- port: 27017
selector:
name: mongo
Then mondgo will be accessible from java application pod with mongo:27017
address.
For a quick experiment you may use kubectl expose pod _MONGO_POD_NAME_ --port=27017 --name=mongo
This tutorial may be handy as well.