title: Kubernetes ensure clients navigate to the same pod from different services
body: <p>I have a Cluster running on AWS EKS and I have 2 services to expose, one of these services works with TCP port while the other one works with UDP port. Clients establish a socket connection in 2 protocols, send the important information over the TCP and unimportant information via UDP.</p>
  <p>When TCP Socket connection is successful, Server generates a SessionId for the client and sends it to the client with a 'Welcome Message', then the Client sends this SessionId to the UDP server, UDP server find the SessionId and send confirmation message to the client from the TCP server. (I don’t use storage to prevent latency, all information stored in memory)</p>
  <p>Step by step assurance for client side;</p>
  <ol>
  <li>Connect to TCP Server and read SessionId.</li>
  <li>Connect to UDP Server and send TCP SessionId.</li>
  <li>Wait for 'Pair Success' message from the TCP server.</li>
  </ol>
  <p>Since I cannot open TCP and UDP ports at the same time through a single service (LoadBalancer) with EKS, I created 2 different services and forwarded these services to the same deployment, but sometimes these services are forwarding to different pods and I cannot pair TCP Session and UDP Endpoint that came from the client.</p>
  <p>Is it possible to ensure 2 different services forward requests to the same pod that came from the same client?
  If not, what kind of architecture should be followed for the current scenario?</p>
  <p>I'm new at k8s and I'm ready to change all my server logic if necessary, feel free to advise me about refactoring the application.</p>
  <p>Here my k8s config.</p>
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: my-app
  spec:
    replicas: 2
    selector:
      matchLabels:
        app: my-app
    template:
      metadata:
        labels:
          app: my-app
      spec:
        shareProcessNamespace: true
        containers:
        - name: my-app
          image: my-ecr/my-app:latest
          ports:
          - containerPort: 27010
          - containerPort: 27011
            protocol: UDP
          env:
        imagePullSecrets:
          - name: regcred
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: my-app-service-tcp
    annotations:
      service.beta.kubernetes.io/aws-load-balancer-type: external
      service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip   
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold: &quot;3&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold: &quot;3&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout: &quot;10&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval: &quot;10&quot;      
      service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
  spec:
    selector:
     app: my-app
    type: LoadBalancer
    ports:
      - name: &quot;tcpsocket&quot;
        protocol: TCP
        port: 27010
        targetPort: 27010
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: my-app-service-udp
    annotations:
      service.beta.kubernetes.io/aws-load-balancer-type: external
      service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: ip
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-port: &quot;27010&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-protocol: TCP 
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold: &quot;3&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold: &quot;3&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout: &quot;10&quot;
      service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval: &quot;10&quot;   
      service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
  spec: 
    selector:
     app: my-app
    type: LoadBalancer
    ports:
      - name: &quot;udpsocket&quot;
        protocol: UDP
        port: 27011
        targetPort: 27011
  </code></pre>