<p>I have two containers inside a Pod with label app=read-write. container-1 is reading on 7110 port and container-2 is listening on 7111. Now I need to connect with these containers via Services NodePorts. I create two separate services to assign NodePorts on each port (7110 and 7111).</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: read
    tier: service
  name: read
spec:
  ports:
  - port: 7110
    nodePort: 32000
    protocol: TCP
  type: NodePort
  selector:
    app: read
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: write
    tier: service
  name: write
spec:
  ports:
  - port: 7111
    nodePort: 32001
    protocol: TCP
  type: NodePort
  selector:
    app: write
</code></pre>

<p>but Services connect with Pods by matching label. So currently these two services will NOT connect with any pod because pod label is <code>read-write</code> and services are looking for any pod with label <code>read</code> or <code>write</code>. Is there any way in kubernetes where we can label containers inside a Pod ? </p>

<p>The only solution I have is to create single container per Pod and assign read and write label to each. But I really want to keep these two containers inside single pod. </p>

<p>The solution was rather simple, I've added two labels (with different keys) in both services,  Instead of <code>app:read</code> and <code>app:write</code>, I've added <code>read: read-service</code> and <code>write: write-service</code> in my services. 
and in the Pod I've added both of these keys under label and selector;</p>

<p>Services readwrite.yml</p>

<pre><code>---
apiVersion: v1
kind: Service
metadata:
  labels:
    read: read-service
    tier: service
  name: read-service
spec:
  ports:
  - port: 7110
    nodePort: 32000
    protocol: TCP
  type: NodePort
  selector:
    read: read-service
---
apiVersion: v1
kind: Service
metadata:
  labels:
    write: write-service
    tier: service
  name: write-service
spec:
  ports:
  - port: 7111
    nodePort: 32001
    protocol: TCP
  type: NodePort
  selector:
    write: write-service
</code></pre>

<p>deployment.yml</p>

<pre><code>kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  creationTimestamp: null
  labels:
    read: read-service
    write: write-service
    tier: service
  name: if11-read-write
spec:
  replicas: 1
  selector:
    matchLabels:
      read: read-service
      write: write-service
  template:
    metadata:
      labels:
        read: read-service
        write: write-service
        tier: service
    spec:
      containers:
      - name: read-container-name
        ...
      - name: write-container-name  
        ...
</code></pre>

<p>Now since both containers are under one Pod and having two labels, So read-service will look-up for a Pod with label <code>read: read-service</code> and assign a port 7110 and NodePort 32000. and write-service will look-up for a Pod with label <code>write: write-service</code> and assign a port 7111 and NodePort 32001. </p>
