Kubernetes: Same node but different IPs

4/20/2020

I have created a K8s cluster on GCP, and I deployed an application.

Then I scaled it:

kubectl scale deployment hello-world-rest-api --replicas=3

Now when I run 'kubectl get pods', I see three pods. Their NODE value is same. I understand it means they all are deployed on same machine. But I observe that IP value for all three is different.

If NODE is same, then why is IP different?

-- Mandroid
kubernetes
kubernetes-pod

2 Answers

4/20/2020

From the kubernetes networking model

Every Pod gets its own IP address. This means you do not need to explicitly create links between Pods and you almost never need to deal with mapping container ports to host ports. This creates a clean, backwards-compatible model where Pods can be treated much like VMs or physical hosts from the perspectives of port allocation, naming, service discovery, load balancing, application configuration, and migration

Kubernetes IP addresses exist at the Pod scope - containers within a Pod share their network namespaces - including their IP address. This means that containers within a Pod can all reach each other’s ports on localhost. This also means that containers within a Pod must coordinate port usage, but this is no different from processes in a VM. This is called the “IP-per-pod” model

https://sookocheff.com/post/kubernetes/understanding-kubernetes-networking-model/

-- Arghya Sadhu
Source: StackOverflow

4/20/2020

There are several networks in a k8s cluster. The pods are on the pod network, so every pod deployed on the nodes of a k8s cluster can see each other as though they are independent nodes on a network. The pod address space is different from the node address space. So, each pod running on a node gets a unique address from the pod network, which is also different from the node network. The k8s components running on each node perform the address translation.

-- Burak Serdar
Source: StackOverflow