How to connect different deployments in Kubernetes?

6/26/2018

I have two back-end deployments, REST server and a database server, each running on some specific ports. The REST server internally calls a database server.

Now how do I refer my database server deployment in my REST server deployment so that they can communicate with each other?

-- Punit Naik
kubectl
kubernetes

2 Answers

6/26/2018
  1. Expose your deployments as service. For example, kubectl expose ...
  2. Connect/Allow these to communicate by creating network policies.

Service object (of database) will give you a virtual (stable) IP. Depending upon the type of service your rest code can call DB via clusterIP/externalName/externalIP/DNS.

-- Prateek Jain
Source: StackOverflow

6/26/2018

first, define a service for your DB server, that will create sort of a loadbalancer (internal kube integration based on iptables in most cases). With that, you will be able to refer to it by service name or fqdn like mydbsvc.namespace.svc.cluster.local. Which will return "Cluster IP" to that loadbalancer.

Then it's just an issue of regular app config to point it to your DB on mydbsvc, preferably by means of env variable like say DB_HOST=mydbsvc set in your REST API deployment manifest (pod template envs)

-- Radek 'Goblin' Pieczonka
Source: StackOverflow