<p>My application has to deployments with a POD. 
Can I create a Service to distribute load across these 2 PODs, part of different deployments ?
If so, How ?                </p>

Chandu
<p>Yes it is possible to achieve. Good explanation how to do it can be found on <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/" rel="nofollow noreferrer">Kubernete documentation</a>. However, keep in mind that <strong>both deployments should provide the same functionality</strong>, as the output should have the same format.</p>

<blockquote>
  <p>A Kubernetes Service is an abstraction which defines a logical set of Pods running somewhere in your cluster, <code>that all provide the same functionality</code>. When created, each Service is assigned a unique IP address (also called clusterIP). This address is tied to the lifespan of the Service, and will not change while the Service is alive. Pods can be configured to talk to the Service, and know that communication to the Service will be automatically load-balanced out to some pod that is a member of the Service.</p>
</blockquote>

<p>Based on example from Documentation.</p>

<p><strong>1.</strong> <code>nginx</code> Deployment. Keep in mind that Deployment can have more than 1 label.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      run: nginx
      env: dev
  replicas: 2
  template:
    metadata:
      labels:
        run: nginx
        env: dev
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80
</code></pre>

<p><strong>2.</strong> <code>nginx-second</code> Deployment</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-second
spec:
  selector:
    matchLabels:
      run: nginx
      env: prod
  replicas: 2
  template:
    metadata:
      labels:
        run: nginx
        env: prod
    spec:
      containers:
      - name: nginx-second
        image: nginx
        ports:
        - containerPort: 80
</code></pre>

<p>Now to <em>pair</em> <code>Deployments</code> with <code>Services</code> you have to use <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="nofollow noreferrer">Selector</a> based on <code>Deployments</code> labels. Below you can find 2 <code>service</code> YAMLs. <code>nginx-service</code> which pointing to both deployments and <code>nginx-service-1</code> which points only to <code>nginx-second</code> deployment.</p>

<pre><code>## Both Deployments
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    run: nginx
---
### To nginx-second deployment
apiVersion: v1
kind: Service
metadata:
  name: nginx-service-1
spec:
  ports:
  - port: 80
    protocol: TCP
  selector:
    env: prod
</code></pre>

<p>You can verify that <code>service</code> binds to deployment by checking the endpoints.</p>

<pre><code>$ kubectl get pods -l run=nginx -o yaml | grep podIP
    podIP: 10.32.0.9
    podIP: 10.32.2.10
    podIP: 10.32.0.10
    podIP: 10.32.2.11
$ kk get ep nginx-service
NAME            ENDPOINTS                                              AGE
nginx-service   10.32.0.10:80,10.32.0.9:80,10.32.2.10:80 + 1 more...   3m33s
$ kk get ep nginx-service-1
NAME              ENDPOINTS                     AGE
nginx-service-1   10.32.0.10:80,10.32.2.11:80   3m36s
</code></pre>
