Home > OS >  Access pod using ip
Access pod using ip

Time:03-04

I have a service exposed, where behind we have several pods for that service. All the traffic to the pods are routed by LB as default .

Now I'm trying to access to one particular pod using the ip from another pod of another service.

Unfortunately I cannot reach it, and is only through the service name defined as usual.

But I need to access to a specific pod since my comunicación let a request open there, and I need to go back to that particular pod, Once I finish my journey.

There's any way to accomplish this, or is totally imposible.

Session affinity won’t help me. This is the flow. Service A pod1 call Service B pod2 passing in the header the local ip. Then pod2 try to call the pod1 using the ip instead the service-name

Regards

CodePudding user response:

pods are scaled out and scaled down. pod ip is ephemeral and cant be relied on. Instead define a service that selects the required pods using selector. you should be accessing the pod using the service.

CodePudding user response:

Session affinity won’t help me.

This is the flow. Service A pod1 call Service B pod2 passing in the header the local ip. Then pod2 try to call the pod1 using the ip instead the service-name

CodePudding user response:

Pods IPs are ephemeral so they are most likely to change every time a pod is re-created. Nevertheless you can check the Kubernetes documentation about DNS for Pods and services. You can setup for your pods a hostname and subdomain so you can reach them via DNS like hostname.subdomain.namespace.svc.cluster.local.

You also may use Headless service. This will give you the IP of one of the pods behind the service and not the service IP, for example:

# nslookup my-not-headless-svc
Server:     10.43.0.10
Address:    10.43.0.10:53

Name:   my-not-headless-svc.default.svc.cluster.local
Address: 10.43.55.35


# nslookup my-headless-svc
Name:   my-headless-svc.default.svc.cluster.local
Address: 10.42.3.103
Name:   my-headless-svc.default.svc.cluster.local
Address: 10.42.2.236
Name:   my-headless-svc.default.svc.cluster.local
Address: 10.42.2.227

Here you can clearly see, using a headless service you will always get one of the pod IPs behind the service and not the serviceIP itself.

  • Related