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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With