<p>I am planning to have a Kubernetes cluster for production using Ingress for external requests.</p>
<p>I have an elastic database that is not going to be part of the Kubernetes cluster. I have a microservice in the Kubernetes cluster that communicates with the elastic database through HTTP (Get,Post etc).</p>
<p>Should I create another NodePort Service in order to communicate with the elastic database or should it be through the Ingress controller as it's an HTTP request? if both are valid options please let me know what is better to use and why</p>

<blockquote>
<p>Should I create another NodePort Service in order to communicate with
the elastic database or should it be through the Ingress controller as
it's an HTTP request?</p>
</blockquote>
<p>There is no requirement of it if your k8s cluster is a public, microservices will be able to send requests to the <strong>Elasticsearch</strong> database.</p>
<p><strong>Ingress</strong> and <strong>Egress</strong> endpoints might not be the same point in <strong>K8s</strong>.</p>
<blockquote>
<p>I have a microservice in the Kubernetes cluster that communicates with
the elastic database through HTTP (Get,Post etc).</p>
</blockquote>
<p>May there is some misunderstanding, Ingress is for the incoming request it's not guarantee when you are running the microservice on Kubernetes your HTTP outgoing egress request will go through the same way.</p>
<p>If your microservice running on the K8s cluster, it will use the Node's IP on which POD is running as outgoing IP.</p>
<p>You can verify this quickly using <strong>kubectl exec</strong> command</p>
<pre><code>kubectl exec -it &lt;Any POD name&gt; -n &lt;namespace name&gt; -- /bin/bash 
</code></pre>
<p>Run the command now</p>
<pre><code>curl https://ifconfig.me
</code></pre>
<p>above command will response with the IP from where the request is going out in your cluster, it will be Node's IP on which your POD is scheduled.</p>
<p><strong>Extra</strong></p>
<p>So you can manage the <strong>ingress</strong> for incoming traffic no extra config is required for <strong>egress</strong> traffic, but if you want to whitelist single IP in the Elasticsearch database then you have to set up the <strong>NAT gateway</strong>.</p>
<p>So all traffic of K8s microservices will go out from a <strong>single</strong> <strong>IP</strong>(Nat gateway's IP), it will be different IP from the <strong>Ingress IP</strong>.</p>
<p>If you are on GCP, here is terraform script to setup the NAT gateway also : <a href="https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway" rel="nofollow noreferrer">https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway</a></p>
<p>You might will get an idea by watching the diagram in the above link.</p>
