title: Route Traffic Into Specific Pod of a Replica Set
body: <p>I need to route traffic (real-time audio/video) directly into specific container of pods. The number of pods should be scaled horizontally with a replica set. My solution now is to create a StatefulSet with as many NodePort-type services as there are pods.</p>
  
  <pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
  kind: StatefulSet
  metadata:
    labels:
      app: foobar
    name: foobar-app
  spec:
    serviceName: foobar
    replicas: 2
    selector:
      matchLabels:
        app: foobar
    template:
      metadata:
        labels:
          app: foobar
      spec:
        containers:
        - image: foobar:latest
          name: foobar
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: foobar-service-0
  spec:
    type: NodePort
    selector:
      statefulset.kubernetes.io/pod-name: foobar-app-0
    ports:
      - protocol: TCP
        nodePort: 30036
        port: 3000
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: foobar-service-1
  spec:
    type: NodePort
    selector:
      statefulset.kubernetes.io/pod-name: foobar-app-1
    ports:
      - protocol: TCP
        nodePort: 30037
        port: 3000
  </code></pre>
  
  <p>Is this considered an acceptable solution or is there a better one for creating services for each pod?</p>