<p>In dockers, I had two containers <code>Mosquitto</code> abd <code>userInfo</code></p>

<p><code>userInfo</code> is a container which performs some logic and then send the result to mosquitto container. Mosquitto container then use this information to send it to IOT hub. To start these containers in Docker, I created a network and started both the container in the same network. So I can easily use the hostname of <code>mosquitto</code> container inside <code>userinfo</code> container to send data. I need to do this same in kubernetes.</p>

<p>So in kubernetes, what I did, I deployed the <code>Mosquitto</code> so its POD was created then I created its service and use it inside the <code>userInfo</code> pod to send data to <code>mosquitto</code>. But this is not working.</p>

<p>I created the service by using </p>

<pre><code>kubectl expose deployment mosquitto
</code></pre>

<p>I need to send data of <code>userInfo</code> to <code>Mosquitto</code>. </p>

<ul>
<li><p>How can I achieve this.? </p></li>
<li><p>Do I need to create network as I was doing in <code>dockers</code> or is there any other way.?</p></li>
</ul>

<p>I also tried creating a pod with two containers i.e. <code>mosquitto</code> &amp; <code>userInfo</code>, but this was also not working.</p>

<p>Thanks</p>

<p>A Kubernetes pod may contain multiple containers. People generally run multiple containers in a pod when the two containers are tightly coupled, and it sounds like this is what you're looking for. These containers are guaranteed to be hosted on the same machine (they can contact each other via localhost), share the same port space, and can also use the same volumes.
<a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#what-is-a-pod" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod/#what-is-a-pod</a></p>
