<p>Currently, I have working K8s API pods in a K8s service that connects to a K8s Redis service, with K8s pods of it's own. The problem is, I am using NodePort meaning BOTH are exposed to the public. I only want the API accessable to the public. The issue is that if I make the Redis service not public, the API can't see it. Is there a way to connect two Services without exposing one to the public?</p>

<p>This is my API service yaml:  </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
   name: app-api-svc
spec:
   selector:
     app: app-api
     tier: api
   ports:
     - protocol: TCP
       port: 5000
       nodePort: 30400
   type: NodePort
</code></pre>

<p>And this is my Redis service yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
   name: app-api-redis-svc
spec:
   selector:
     app: app-api-redis
     tier: celery_broker
   ports:
     - protocol: TCP
       port: 6379
       nodePort: 30537
   type: NodePort
</code></pre>

<p>First, configure the Redis service as a <code>ClusterIP</code> service. It will be private, visible only for other services. This is could be done removing the line with the option <code>type</code>.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
   name: app-api-redis-svc
spec:
   selector:
     app: app-api-redis
     tier: celery_broker
   ports:
     - protocol: TCP
       port: 6379
       targetPort: [the port exposed by the Redis pod]
</code></pre>

<p>Finally, when you configure the API to reach Redis, the address should be <code>app-api-redis-svc:6379</code></p>

<p>And that's all. I have a lot of services communicating each other in this way. If this doesn't work for you, let me know in the comments.</p>
