I am new to kubernetes, just wanted to know if my question is valid.
I had a question if a single POD can host 2 or more services.
And If it can host multiple services, how can it differentiate the traffic between the services.
Does it do a PORT mapping.
Please, let me know.
a single POD can host 2 or more services?
I am assuming that, by services you meant Docker containers. If that's not the case, please let me know.
Yes, Single pod can host more than one containers.
how can it differentiate the traffic between the services.
That's the catch. You need to deal with it using the ports. Expose one service on one a port and another on a different port. (If you want more than one service/container to be exposed from the same pod rethink about your design, it may be an ideal candidate for a different pod)
That being said, Now let's see the best practices,
When should I use 2 Docker containers in a pod
If your both services (docker containers) are tightly coupled and when you scale one service you need to scale the other along with the former. (Trust me, this very rare scenario). Usually these are referred as side-cars.
When should use different pod for different
If you want to scale each of them independent of the other.
Examples
You can add multiple containers to the same pod, but that's only recommended if the services are tightly coupled, like if they need to communicate. For example, if you have a web server and a sql database, you would likely want them in the same pod.
If the services are distinct, you would likely want to put them in different pods, but deploy them to the same cluster of nodes. Then, you can have a LoadBalancer service on the cluster that can route different ports or paths to the right pod. In this way, the services can be scaled and managed separately (and without worrying about port conflicts), but they still draw from the same pool of resources