How to do mulit pods deployment in kubernetes

3/7/2018

I have two docker images Mosquitto & user-info. userInfo is a container which performs some logic and then send the result to mosquitto. Mosquitto then use this information to send it to IOT hub. Inside user-info I have mentioned to use hostname=mosquitto so the user-info send all data to mosquitto

I started first by creating a pods with these 2 containers. So I wrote a yaml file with kind: Pod and everything went ok. As these container were inside the same pod, so they were easily able to communicate to each other and hence user-info was able to send data to mosquitto.

Now going forward I do not want to create pods and would like to go with kind: Deployment but I wonder creating multiple pods is not possible in deployment. So if I create two deployment files for mosquitto-deployment.yaml & user-info-deployment.yaml, they both will create two different pods. So how can I make these pods communicate?

I read about service and we can communicate using service but I am having hard time with services. If I create a service for mosquitto, do I need to create service for user-info or it can directly communicate to mosquitto service. Also, is it not possible to use single deployment.yaml file for creating all the pods rather than using 2-3 deployment.yaml files.

-- S Andrew
deployment
docker
kubernetes

2 Answers

3/7/2018

Having two distinct softwares in separate deployments make sense. You can have them both in single yaml file as long as you separate them with --- delimiter line, but that is essentialy the same as having separate file for each of them.

You need a service for a group of pods (0-N) to which something in your cluster (or outside for NodePort and LB svc) needs to connect to, so in your case you only need svc for Mosquitto, unless something else would also talk with user-info.

You can think about service as a loadbalancer sitting in front of selected group of pods.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow

3/7/2018

A quote from the book "Up and running with Kubernetes" should give you a hint;

In general, the right question to ask yourself when designing Pods is, “Will these containers work correctly if they land on different machines?” If the answer is “no,” a Pod is the correct grouping for the containers. If the answer is “yes,” multiple Pods is probably the correct solution.

From what I've read about your project, those two containers would be more of a fit for a single pod - and that way they can communicate through localhost.

In general, you will never need a k8 manifest with the kind pod, thats just for experimental purposes.

For a typical app you will need an deployment and service object.

Tom

-- Tomislav Mikulin
Source: StackOverflow