I am trying to run a p2p client (IOTA) which requires the node I am connecting to to be able to connect back to be on the same ip address I made the request from and to a very specific port.
NodePort won't work because it exposes as a different port then what I want. LoadBalancer won't work because the other node won't know my load balancer ip address.
How are people able to use p2p clients like bitcoin or iota on kubernetes?
Because each pod has a dynamic IP address and, usually, a dynamic name (for example, if you use Deployment
), you don't have a chance to make its' endpoint static somehow, but you have an alternative way - StatefulSet with Headless Service.
You can deploy several replicas of your application using StatefulSet
and create Headless Service
for it. Each replica in the StatefulSet
will be available using its unique name.
Here's the quote from the documentation:
Each
Pod
in aStatefulSet
derives its hostname from the name of theStatefulSet
and the ordinal of the Pod. The pattern for the constructed hostname is$(statefulset name)-$(ordinal)
. The example above will create three Pods namedweb-0
,web-1
,web-2
. AStatefulSet
can use aHeadless Service
to control the domain of itsPods
. The domain managed by thisService
takes the form:$(service name).$(namespace).svc.cluster.local
, where “cluster.local” is the cluster domain. As eachPod
is created, it gets a matching DNS subdomain, taking the form:$(podname).$(governing service domain)
, where the governing service is defined by theserviceName
field on theStatefulSet
.