<p>I am running Kubernetes on "Docker Desktop" in Windows.</p>

<p>I have a LoadBalancer Service for a deployment which has 3 replicas.
I would like to access SPECIFIC pod through some means <em>(such as via URL path : &lt; serviceIP >:8090/pod1)</em>.</p>

<p>Is there any way to achieve this usecase?</p>

<hr>

<p><strong>deployment.yaml :</strong></p>

<blockquote>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-service1
  labels:
    app: stream
spec:
  ports:
  - port: 8090
    targetPort: 8090
    name: port8090
  selector:
    app: stream
  # clusterIP: None
  type: LoadBalancer
---
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: stream-deployment
  labels:
    app: stream
spec:
  replicas: 3
  selector:
    matchLabels:
      app: stream
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: stream
    spec:
      containers:
      - image: stream-server-mock:latest
        name: stream-server-mock
        imagePullPolicy: Never
        env:
        - name: STREAMER_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: STREAMER_ADDRESS
          value: stream-server-mock:8090
        ports:
        - containerPort: 8090
</code></pre>
</blockquote>

<hr>

<p><strong>My end goal is to achieve horizontal auto-scaling of pods.</strong></p>

<p><strong>How Application designed/and works as of now (without kubernetes) :</strong></p>

<blockquote>
  <p>There are 3 components : REST-Server, Stream-Server (3 instances
  locally on different JVM on different ports), and RabbitMQ.</p>
</blockquote>

<pre><code>1 - The client sends a request to "REST-Server" for a stream url.
2 - The REST-Server puts in the RabbitMQ queue.
3 - One of the Stream-Server picks it up and populates its IP and sends back to REST-Server through RabbitMQ.
4 - The client receives the IP and establishes a direct WS connection using the IP.
</code></pre>

<p><strong>The Problem what I face is</strong> :</p>

<pre><code>1 - When the client requests for a stream IP, one of the pods (lets say POD1) picks it up and sends its URL (which is service URL, comes through LoadBalancer Service).
2 - Next time when the client tries to connect (WebSocket Connection) using the Service IP, it wont be the same pod which accepted the request.
</code></pre>

<p><strong>It should be the same pod which accepted the request, and must be accessible by the client.</strong></p>

<p>You can use <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="noreferrer">StatefulSets</a> if you are not required to use deployment.</p>

<p>For replica 3, you will have 3 pods named</p>

<ol>
<li>stream-deployment-0</li>
<li>stream-deployment-1</li>
<li>stream-deployment-2</li>
</ol>

<p>You can access each pod as <code>$(podname).$(service name).$(namespace).svc.cluster.local</code></p>

<p>For details, check <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#stable-network-id" rel="noreferrer">this</a></p>

<p>You may also want to set up an ingress to point each pod from outside of the cluster.</p>
