<p>In my k8s cluster I have two pods podA and podB. Both are in same k8s cluster. Microservice on pod B is a spring boot rest api. Microservice on pod A have ip and port of pod B in its application.yaml. now every time when  podB recreates, ip change which forces us to change ip in application.yml of podA. Please suggest a better way.</p>

<p>My limitation is : I can't change the code of podA.</p>

<p>A <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a> will provide a consistent DNS name for accessing Pods.</p>
<p>An application should never address a Pod directly unless you have a specific reason to (custom load balancing is one I can think of, or StatefulSets where pods have an identity).</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
</code></pre>
<p>You will then have a consistent DNS name to access any Pods that match the <code>selector</code>:</p>
<pre><code>my-service.default.svc.cluster.local
</code></pre>
