Kubernetes: multiple pods in a node when each pod exposes a port

7/12/2016

I was following along with the Hello, World example in Kubernetes getting started guide.

In that example, a cluster with 3 nodes/instances is created on Google Container Engine.

The container to be deployed is a basic nodejs http server, which listens on port 8080.

Now when I run
kubectl run hello-node --image <image-name> --port 8080
it creates a pod and a deployment, deploying the pod on one of nodes.

Running the
kubectl scale deployment hello-node --replicas=4
command increases the number of pods to 4.

But since each pod exposes the 8080 port, will it not create a port conflict on the pod where two nodes are deployed? I can see 4 pods when I do kubernetes get pods, however what the behaviour will be in this case?

-- Jatin
docker
google-kubernetes-engine
kubernetes

2 Answers

7/12/2016

Got some help in #kubernetes-users channel on slack :

  1. The port specified in kubectl run ... is that of a pod. And each pod has its unique IP address. So, there are no port conflicts.
  2. The pods won’t serve traffic until and unless you expose them as a service.
  3. Exposing a service by running kubectl expose ... assigns a NodePort (which is in range 30000-32000) on every node. This port must be unique for every service.
  4. If a node has multiple pods kube-proxy balances the traffic between those pods.

Also, when I accessed my service from the browser, I was able to see logs in all the 4 pods, so the traffic was served from all the 4 pods.

-- Jatin
Source: StackOverflow

7/12/2016

There is a difference between the port that your pod exposes and the physical ports on your node. Those need to be linked by for instance a kubernetes service or a loadBalancer as discussed a bit further in the hello-world documentation http://kubernetes.io/docs/hellonode/#allow-external-traffic

-- Mark van Straten
Source: StackOverflow