Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communicate between pods in kubernetes

Tags:

kubernetes

I have something like this:

           POD-1
             |
 -------------------------
 ?|?        ?|?        ?|?
service-1 service-2 service-3

How do I communicate from a server inside a pod, to other servers in pods behind services?

like image 830
Liron Navon Avatar asked Dec 27 '18 07:12

Liron Navon


1 Answers

You need to have services for the pod that you want to access. You can just use internal endpoints of the corresponding services of the pod.

As example let's think there is a mysql pod and service corresponding to it as mysql-svc of type ClusterIP exposing port 3306 as below.

apiVersion: v1
kind: Service
metadata:
  name: mysql-svc
spec:
  ports:
  - name: db-port
    protocol: "TCP"
    port: 3306
    targetPort: 3306
  selector:
    app: mysql

And there is a separate pod of python application which uses that mysql. yo can access that mysql server inside pod using mysql://mysql-svc:3306/dbName which is the internal endpoint of mysql-svc

And if your pods are in two different namespaces (mysql in dev namespace and python app in qa namespace) you can use mysql-svc.dev.svc.cluster.local instead.

like image 96
Hansika Weerasena Avatar answered Sep 28 '22 10:09

Hansika Weerasena