<p>I want to deploy two apps &quot;A&quot; and &quot;B&quot; on our Kubernetes cluster (a first for me).</p>
<p>&quot;A&quot; handles traffic from outside the cluster and can request further data from &quot;B&quot; over http. &quot;B&quot; needs much more resources than &quot;A&quot; as it's CPU and Memory intensive.</p>
<p>&quot;A&quot; and &quot;B&quot; are quite tied together since the body of the HTTP calls between them is versioned and quite complex, but &quot;B&quot; should be free to scale independently from &quot;A&quot;.</p>
<p>Today, &quot;A&quot; calls &quot;B&quot; using a dedicated Service whose url is hardcoded in &quot;A&quot;.</p>
<p>During deployment earlier today, &quot;A&quot; and &quot;B&quot; were deployed simultaneously but &quot;A&quot; managed to call an old version of &quot;B&quot; (since the Service was still routing requests to old &quot;B&quot; for a few seconds/minutes).</p>
<p><strong>What's the good practice to tie calls from newly deployed &quot;A&quot; to newly deployed &quot;B&quot; pods only?</strong></p>
<p>I don't want to have a conditional processing in &quot;A&quot; based on the version of the payload received from &quot;B&quot;.</p>
<p>Thank your for your help,</p>

MissouPower
<p>I presume you're just working with native Kubernetes resources, so the most simple way to do this would be to deploy your new backend <code>B</code> separately with different labels than the previous version. Once all pods are up, you simply change the service'es label selectors, this would instantly switch all the traffic to the newly created backend pods.</p>
<p>If you were to update the current backend <code>B</code> this would, depending on the numbers of pods, cause a RollingUpdate by default, so there would be a timeframe where requests could reach the old and newly created backend <code>B</code>'s pods.</p>
<p>However there's special tools that solve such issues in a more &quot;clean&quot; way, such as Argo Rollouts. But If this is your only use-case I would recommend the first method as this causes a sudden switch of all traffic.</p>
<p>Let's assume your backend <code>b</code> looks like the following:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: backend-b
  labels:
    app.kubernetes.io/name: backend-b
spec:
  containers:
  - name: nginx
    image: nginx:stable
    ports:
      - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: backend-b-service
spec:
  selector:
    app.kubernetes.io/name: backend-b
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
</code></pre>
<p>Now you would create a second backend B, please note the different label:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: backend-b-new
  labels:
    app.kubernetes.io/name: backend-b-new
spec:
  containers:
  - name: nginx
    image: nginx:stable
    ports:
      - containerPort: 80
</code></pre>
<p>Currently there would be no traffic hitting this new backend, in order to cause all traffic to switch instantly to the new backend, you would need to change the label selectors of the service for backend B.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: backend-b-service
spec:
  selector:
    app.kubernetes.io/name: backend-b-new
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
</code></pre>
<p>As I said, this isn't the best solution, but should work for your use cases, provided that your Application <code>A</code> is communicating with Application B through the DNS name of the given Service.</p>
