A Pod(P) consists of two containers i.e. C1 and C2.
C1 listens on port 8081
C2 listens on port 8082.
Is it possible to use different ports for the containers inside the ‘same’ pod.
Assuming the above is possible, how can a (nodePort) service forward the traffic to the Pod.
What should be the targetPort defined for this service in this case. Should it have 2 targetPorts and is it possible to configure?
What should be the solution for such kind of requirement(where different containers use different Ports to receive traffic).
That doesn’t sound like an ideal design to me. Sounds like you’re running two separate applications in the same pod, which you should really do as two separate pods. The use case for multiple containers is when the other containers perform support functions for the main application container (init, sidecar, ambassador etc), when overall there would only be one port exposed by the pod to the outside world.
That aside. you should be able to achieve what you are describing by creating two services, one for each port but both services having the same pod selector. A service object can only target one port at a time, hence two services.
Thank you so much for the clear explanation @Alistair_KodeKloud
Yes, it doesnt make sense to have multiple containers inside a pod offering different svc, instead separate pods could be deployed.
The other option you highlighted, wherein 2 different svc with 2 targetPorts but with similar label selector(ofcourse this may be changed as well) can also be achieved.
Once again, thank you for sharing the information.