Expose a specific port to be accessible by my outgoing ip address on kubernetes

5/15/2018

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?

-- Mr_E
kubernetes

1 Answer

5/22/2018

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 a StatefulSet derives its hostname from the name of the StatefulSet and the ordinal of the Pod. The pattern for the constructed hostname is $(statefulset name)-$(ordinal). The example above will create three Pods named web-0,web-1,web-2. A StatefulSet can use a Headless Service to control the domain of its Pods. The domain managed by this Service takes the form: $(service name).$(namespace).svc.cluster.local, where “cluster.local” is the cluster domain. As each Pod is created, it gets a matching DNS subdomain, taking the form: $(podname).$(governing service domain), where the governing service is defined by the serviceName field on the StatefulSet.

-- Anton Kostenko
Source: StackOverflow