简体   繁体   中英

Bind application pod and database pod in kubernetes

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 eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM