<p>I have two services deployed on the same k8s (minikube cluster).  What is the url/approach I should use for one service to communicate with another service.  I tried searching a bit on the web but most of them are communicating with an external db which is not what I'm after.  This is what my deployments look like.  I am looking for the goclient to be able to communicate with goserver.  I know I need to go through the service but not sure what the url should look like.  And is this dynamically discoverable?  In addition to this if I expose goserver though <code>ingress</code> will this change ?</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: goserver
  namespace: golang-ns
  labels:
    app: goserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: goserver
  template:
    metadata:
      labels:
        app: goserver
    spec:
      containers:
      - name: goserver
        image: goserver:1.0.0
        imagePullPolicy: Never
        ports:
        - containerPort: 8080

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: goclient
  namespace: golang-ns
  labels:
    app: goclient
spec:
  replicas: 1
  selector:
    matchLabels:
      app: goclient
  template:
    metadata:
      labels:
        app: goclient
    spec:
      containers:
      - name: goclient
        image: goclient:1.0.0
        imagePullPolicy: Never
        ports:
        - containerPort: 8081

---

apiVersion: v1
kind: Service
metadata:
  name: goserver-service
  namespace: golang-ns
spec:
  selector:
    app: goserver  
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  type: LoadBalancer

---

apiVersion: v1
kind: Service
metadata:
  name: goclient-service
  namespace: golang-ns
spec:
  selector:
    app: goclient
  ports:
    - protocol: TCP
      port: 8081
      targetPort: 8081
  type: LoadBalancer
</code></pre>

tmp dev
<p>Note that the term <em><strong>Service</strong></em> can be quite ambiguous when used in the context of <strong>kubernetes</strong>.</p>
<p><strong>Service</strong> in your question is used to denote one of your <strong>microservices</strong>, deployed as containerized applications, running in <code>Pods</code>, managed by 2 separate <code>Deployments</code>.</p>
<p><code>Service</code>, that was mentioned in David Maze's comment, refers to a specific resource type which is used for exposing your apps/microservices both inside and outside your <strong>kubernetes cluster</strong>. This resource type is called a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="noreferrer"><code>Service</code></a>. But I assume you know that as such <code>Services</code> are also added in your examples.</p>
<p>This is the reason why I prefer to use a term <strong><em>microservice</em></strong> if I really want to call <em>&quot;a service&quot;</em> one of the apps (clients, servers, whatever... ) deployed on my <strong>kubernetes cluster</strong>. And yes, this is really important distinction as talking about communication from one <code>Service</code> to another <code>Service</code> (kubernetes resource type) doesn't make any sense at all. Your <code>Pod</code> can communicate with a different <code>Pod</code> via a <code>Service</code> that exposes this second <code>Pod</code>, but <code>Services</code> don't communicate with each other at all. I hope this is clear.</p>
<p>So in order to expose one of your <strong>microservices</strong> <strong>within your cluster</strong> and make it easily accessible for other <strong>microservices</strong>, running on the same cluster, use a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="noreferrer"><code>Service</code></a>. But what you really need in your case is it's simplest form. ❗<strong>There is no need for using <code>LoadBalancer</code> type here</strong>. In your case you want to expose your <code>Deployment</code> named <code>goserver</code> to make it accessible by <code>Pods</code> from second <code>Deployment</code>, named <code>goclient</code>, not by external clients, sending requests from the public Internet.</p>
<p>Note that <a href="https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/" rel="noreferrer"><code>LoadBalancer</code></a> type that you used in your <code>Service</code>'s yaml manifests has completely different purpose - it is used for exposing your app for clients reaching to it from outside your <strong>kubernetes cluster</strong> and is mainly applicable in cloud environments.</p>
<p>So again, what you need in your case is the simplest <code>Service</code> (often called <code>ClusterIP</code> as it is the default <code>Service</code> type) which exposes a <code>Deployment</code> <strong>within</strong> the cluster. ⚠️ Remember that <code>ClusterIP</code> <code>Service</code> also has loadbalancing capabilities.</p>
<p>OK, enough of explanations, let's move on to the practical part. As I said, it's really simple and it can be done with one command:</p>
<pre><code>kubectl expose deployment goserver --port 8080 --namespace golang-ns
</code></pre>
<p>Yes! That's all! It will create a <code>Service</code> named <code>goserver</code> (there is no reason to name it differently than the <code>Deployment</code> it exposes) which will expose <code>Pods</code> belonging to <code>goserver</code> <code>Deployment</code> within your <strong>kubernetes cluster</strong>, making it easily accessible (and discoverable) via it's <a href="https://kubernetes.io/docs/concepts/services-networking/service/#dns" rel="noreferrer">DNS</a> name.</p>
<p>If you prefer declarative <code>Service</code> definition, here it is as well:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: goserver
  namespace: golang-ns
spec:
  selector:
    app: goserver  
  ports:
    - port: 8080
</code></pre>
<p>Your <code>golang-client</code> <code>Pods</code> need only the <code>Service</code> name i.e. <code>goserver</code> to access <code>goserver</code> <code>Pods</code> as they are deployed in the same namespace (<code>golang-ns</code>). If you need to access them from a <code>Pod</code> deployed to a different namespace, you need to use <code>&lt;servicename&gt;.&lt;namespace&gt;</code> i.e. <code>goserver.golang-ns</code>. You can also use <strong>fully quallified domain name (FQDN)</strong> (see the official docs <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#services" rel="noreferrer">here</a>):</p>
<pre><code>my-svc.my-namespace.svc.cluster-domain.example
</code></pre>
<p>which in your case may look as follows:</p>
<pre><code>goserver.golang-ns.svc.cluster.local
</code></pre>
<p>As to:</p>
<blockquote>
<p>In addition to this if I expose goserver though ingress will this
change ?</p>
</blockquote>
<p>❗Unless you want to expose your <code>goserver</code> to the external world, don't use <code>Ingress</code>, you don't need it.</p>
