<p>I have a K8s service defined as:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    name: myapp
  name: myapp
  namespace: myapps

spec:
  ports:
    - name: ui
      port: 8081
      protocol: TCP
      targetPort: 8081
  selector:
    my-app: myapp
    my-deployment-type: jobmanager
  type: ClusterIP
</code></pre>
<p>This service serves as backend for an ingress.</p>
<p>Now during blue green deployment there are two apps running i.e two sets of pods that match the selctors specified above:
my-app: myapp
my-deployment-type: jobmanager</p>
<p>And I observe that it selects both pods i.e both app versions at random till the older app pods gets killed.</p>
<p>Is there a way to ensure that the service will just choose the new app pods? i.e Have a selector to also depend on the &quot;Start Time&quot; of the pods apart from the selector?</p>

Ace McCloud
<blockquote>
<p>Is there a way to ensure that the service will just choose the new app pods? i.e Have a selector to also depend on the &quot;Start Time&quot; of the pods apart from the selector?</p>
</blockquote>
<p>There is no such feature in Kubernetes to filter a pod start time in service selector block.</p>
<p>The <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#service-and-replicationcontroller" rel="nofollow noreferrer">official k8s documentation</a> says ¨Labels selectors for service objects are defined in json or yaml files using maps, and <strong>only equality-based requirement selectors are supported</strong> ¨.</p>
<p>So, in your case the best option is to:</p>
<ul>
<li>create a new k8s deployment with new labels for green deployment (the new application version)</li>
<li>create a new ClusterIP service for the green deployment</li>
<li>then switch your Ingress to this green deployment by changing the backend service name.</li>
</ul>
<p>If something goes wrong, you can quickly switch back to your blue deployment (previous application version).</p>
