How to assign static IP address or HostName to node and POD

Asking for help? Comment out what you need so we can get more information to help you!

We have a setup where we want to run 3 replicas of our Image. Each replica will be run in independent node and corresponding pods inside it.
So to summarize we will have 3 nodes in 3 separate JVMs and 3 corresponding pods.
Please answer,

  1. Can the Node IP and hostname be same as machine IP and hostname?
  2. Can the same Machine IP and hostname be made POD IP and hostname?
  3. Can we fix POD IP and hostName always?

Cluster information:

Kubernetes version:
Cloud being used: (put bare-metal if not on a public cloud)
Installation method:
Host OS:
CNI and version:
CRI and version:

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

I hope I got the question right…

  1. Machine IP and node IP should be the same …
  2. You can use hosrnetwork in the pods ( deployment or sts) yaml configuration …though I would strongly advise you not to do so and find a different solution.
  3. To keep pod hostname fixed you can use sts (statefulset) along with a headless service which will result in pods with static hostnames at all times

If you could provide some more details and what you are trying to achieve maybe there is a more elegant solution .

@Theog75 , Our setup is like this, we have 3 different JVMs, where each JVM will have a single node and a single pod associated with it(3 replicas in 3 individual nodes and JVM). So when we have a fixed JVM/System name, we were thinking of fixing the IP:PORT for each pod so that communication to respective pods would be easier.

There are cases where our third party apps needs to communicate with each pod individually, so we are looking for a solution where we can either fix POD IP:PORT or node IP:PORT. Please advise

based on the info you supplied I would use:

  1. a statefulset deployment where pod named are kept the same between deployments (for example if the statefuleset is called jvm the pods it deploys will be called jvm-0,jvm-1 and jvm-2).
  2. use a service for normal communication (LB communication meaning communicatoin sent to this service would be sent to one of the jvm pods randomly - you can use sticky sessions to keep communication with a specific pod per session).
  3. I would create an additional headless service (see headless service) to send communication directly to a specific pod - the way it would work is by using the pod name and the service name to access a specific pod i.e. jvm.jvm-1:8080 as a hostname.(replace 8080 with your port).
  4. in order to make sure pods do not deploy on the same node I would use podAntiAffinity along with requiredDuringSchedulingIgnoredDuringExecution in the affinity configuration (see advance scheduling)
1 Like