<p>I have a little java project that needs to be deployed with kubernetes.
After studying kubernetes for a little while, I have two questions.</p>

<p>Since the projects needs beside the java app, rabbitmq and redis, clearly those three thing need to have three docker images.</p>

<p>1.) Can I put the java app, rabbitmq and redis containers/images into a single pod or should they be in separete pods (I was advised to put them on the same pod)?</p>

<p>Since this is a java app (with a build .jar file) is has a foobar.conf file that has the configurations for the app, like the redis/rabbitmq hostnames and ports and other stuff in it.</p>

<pre><code>  rabbitmq{
        host="$RABBITMQ_HOSTNAME"
        username="rabbitmq"
        password="rabbitmq"
        status-queue-name="foobar-status"
        audit-queue-name="foobar-audit"
        event-queue-name="foobar-events"
        incoming-messages-queue-name="foobar-incoming-messages"
        acknowledge-queue-name="foobar-acknowledge"
  }
</code></pre>

<p>So, how do I expose the redis and rabbitmq containers ports and hostnames (when they spin up) to the foobar.conf files for the app?</p>

<p>Tnx,
Tom</p>

Tomislav Mikulin
<p>Yes, you will need three docker images one for each of the components of your application stack - application, redis and rabbitmq. Also, it is a good idea to put all of those components in a single pod. Microservices usually will need sidecars to fully function and Kubernetes pods exist just to address that need.</p>

<p>But please note that docker containers are stateless in nature. So, if kubernetes decides to move your pod to a different node, then the containers running your service will be destroyed and will be recreated on a different node. All the data that is written to the local filesystem inside the container by any of the three components is lost in the process. If you are aware of that and you have designed your app to be stateless then you should be alright. If not, please explore <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/" rel="nofollow noreferrer">persistent volumes</a> in kubernetes to preserve the state of your pods when they are moved around. You can find more information on configuring your pod to use persistent volumes <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/" rel="nofollow noreferrer">here</a></p>

<p>To answer your second question, there is bunch of ways you can configure your app to communicate with rabbitmq and redis services. Since all the containers in a pod have the same IP and share the same port namespace, you can literally configure the other two services to talk on localhost and standard ports for those two services. However, if you decide to expose those two services to other service with in the cluster network you can still do so by using the pod ip and the ports that you start those two services on.</p>

<p>If you want to expose those two services outside your cluster network, you have to do so via <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">kubernetes services</a> of type <a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport" rel="nofollow noreferrer">NodePort</a>.</p>

<p>Hope that helps.</p>
