<p>I think that you can configure this in the <code>-service.yaml</code>. For example I have a frontend and a backend. The frontend should be public and my backend should be private. So how do you set up two microservices that communicate with each other, one being public and one private, using Kubernetes?</p>
<p>frontend-service.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: frontend
  name: frontend
spec:
  ports:
  - port: 8081
    protocol: TCP
    targetPort: 8081
  selector:
    app: frontend
  type: LoadBalancer
status:
  loadBalancer: {}
</code></pre>
<p>backend-service.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: backend
  name: backend
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: backend
  type: LoadBalancer
status:
  loadBalancer: {}
</code></pre>
<p>What I tried</p>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f frontend-deploy.yaml
kubectl get pods
kubectl apply -f frontend-service.yaml
kubectl get service
</code></pre>
<pre class="lang-sh prettyprint-override"><code>kubectl apply -f backend-deploy.yaml
kubectl get pods
kubectl apply -f backend-service.yaml
kubectl get service
</code></pre>
<pre class="lang-sh prettyprint-override"><code>kubectl expose deployment frontend --type=LoadBalancer --name=frontend-service.yaml
</code></pre>

<p>You should use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">ClusterIP type</a> for the private / internal services which will make your application only available within the cluster:</p>
<blockquote>
<ul>
<li><code>ClusterIP</code>: Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default  <code>ServiceType</code></li>
</ul>
</blockquote>
<p>...and <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">LoadBalancer type</a> for the public services which are designed to receive requests from the outside the cluster:</p>
<blockquote>
<ul>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer" rel="nofollow noreferrer"><code>LoadBalancer</code></a>: Exposes the Service externally using a cloud provider's load balancer.  <code>NodePort</code>  and  <code>ClusterIP</code>  Services, to which the external load balancer routes, are automatically created.</li>
</ul>
</blockquote>
<p>Example:</p>
<p>Let's say that I have created frontend and backend deployments - frontend on 8081 port and backend on 8080. Services yamls are similar to yours (I used LoadBalancer for the frontend, and ClusterIP for the backend). Fronted service is available at the 80 port, backend at the 8080:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: Service
metadata:
  labels:
    app: frontend
  name: frontend
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8081
  selector:
    app: frontend
  type: LoadBalancer
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: backend
  name: backend
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    app: backend
  type: ClusterIP
</code></pre>
<p>Let's check the services:</p>
<pre class="lang-sh prettyprint-override"><code>$ kubectl get svc
NAME                                TYPE           CLUSTER-IP     EXTERNAL-IP      PORT(S)        AGE
backend                             ClusterIP      10.36.9.41     &lt;none&gt;           8080/TCP       19m
frontend                            LoadBalancer   10.36.4.172    xx.xxx.xxx.xxx   80:32126/TCP   19m
</code></pre>
<p>As can see, both services have ClusterIP (used for communication inside the cluster) and frontend service has a LoadBalancer with public IP.</p>
<p>Let's <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/" rel="nofollow noreferrer">exec into a pod</a> and send request to the frontend and backend using just a service name:</p>
<pre class="lang-sh prettyprint-override"><code>root@my-nginx-deployment-5bbb68bb8f-jgvrk:/# curl backend:8080
&quot;hello world backend&quot;
root@my-nginx-deployment-5bbb68bb8f-jgvrk:/# curl frontend:80
&quot;hello world frontend&quot;
</code></pre>
<p>It's working properly, because the pod that I exec into is in the same namespace (default). For communication between different namespaces you <a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/#does-the-service-work-by-dns-name" rel="nofollow noreferrer">should use <code>&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local</code> or ClusterIP</a>:</p>
<pre><code>root@my-nginx-deployment-5bbb68bb8f-jgvrk:/# curl backend.default.svc.cluster.local:8080
&quot;hello world backend&quot;
root@my-nginx-deployment-5bbb68bb8f-jgvrk:/# curl 10.36.9.41:8080
&quot;hello world backend&quot;
</code></pre>
<p>This is how communication inside cluster works in Kubernetes</p>
<p>For requests outside the cluster use LoadBalancer IP (<code>EXTERNAL-IP</code> in the <code>kubectl get svc</code> command):</p>
<pre class="lang-sh prettyprint-override"><code>user@shell-outside-the-cluster:~$ curl xx.xxx.xxx.xxx
&quot;hello world frontend&quot;
</code></pre>
<p>Consider using <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">Ingress</a> when you have multiple applications which you want to expose publicly.</p>
<p>Also check these:</p>
<ul>
<li><a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-services/" rel="nofollow noreferrer">Access Services Running on Clusters | Kubernetes</a></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service | Kubernetes</a></li>
<li><a href="https://kubernetes.io/docs/tasks/debug-application-cluster/debug-service/" rel="nofollow noreferrer">Debug Services | Kubernetes</a></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">DNS for Services and Pods | Kubernetes</a></li>
</ul>
