<p>I have a Deployment with 5 replicas. All have ssh and telnet. They should not be load balanced. I would like each to select from a predictable list of 5.</p>

<p>Here is my Deployment</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 5
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myapp:1.0
        ports:
        - name: ssh
          protocol: TCP
          containerPort: 22
        - name: telnet
          protocol: TCP
          containerPort: 23
</code></pre>

<p>This is my Service with invalid nodePort values for illustrative purposes.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: myapp
  labels:
    app: myapp
spec:
  type: NodePort
  ports:
  - name: ssh
    port: 22
    nodePort: [30022, 30122, 30222, 30322, 30422, 30522]
  - name: telnet
    port: 23
    nodePort: [30023, 30123, 30223, 30323, 30423, 30523]
</code></pre>

<p>I am hoping to be able to accomplish 2 things:</p>

<ol>
<li>Each pod replica instance will only get an ssh port from [30022, 30122, 30222, 30322, 30422, 30522] and a telnet port from [30023, 30123, 30223, 30323, 30423, 30523]</li>
<li>A pod replica instance that gets an ssh port of 30022 also gets the telnet port 30023. A pod replica instance that gets an ssh port of 30122 gets a telnet port of 30123 and so on.</li>
</ol>

<p>Thank you!</p>

Daniel
<p>Consider that the concept of <em>"Replica"</em> means that is going to be the same as the others; a <em>clone</em>.</p>

<p>Based on your question, you need to have unique objects, based on a template, so neither <code>Deployment</code> nor <code>StatefulSet</code> could help as these rely on a <code>ReplicaSet</code>.</p>

<p>As for the <code>StatefulSet</code> labels approach, I'd rather say that is more like a <em>many-to-one</em> relationship, meaning that the whole <code>Service</code> is going to be linked to a particular pod. This means that all the ports mapped in the <code>NodePort</code> service are going to serve an specific pod in the set. If my understanding is correct, you rather want a <em>one-to-one</em> relationship between exposed ports and pods.</p>

<p>Since services act like a load balancer, routing incoming requests to the exact same target (port) on each backend (replica from a deployment), the kind of uniquess that you need might be best approached having each separately, as <code>Deployment</code> or <code>StatefulSet</code> with their corresponding <code>NodePort</code> service and mapping your ports according to your need for <strong>each case</strong>.</p>

<p>This approach of course has a high operational overhead but can cope with the level of uniqueness that your use case requires.</p>
