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?
Got some help in #kubernetes-users
channel on slack :
kubectl run ...
is that of a pod
. And each pod has its unique IP address. So, there are no port conflicts.service
.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.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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With