<p>I try to deploy 2 replicas on <strong>k3s</strong> - each one to a different node. According to documentation, it should be pretty easy. However, I must be doing some silly mistake I am not able to find. When I apply the deploy file, both of my pods are running the same node (<em>node1</em>). In case I switch that node off, these pods start on another 2 nodes (<em>node2</em>, <em>node3</em>). When I start the <em>node1</em> back and redeploy the app, it runs again on the same node1.
If somebody can advise please, what I have wrong in my configuration, I would be really grateful.
(I run fresh new k3s on 3 servers with the same HW configuration)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tbd-node-js-runner
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tbd-node-js-runner
  template:
    metadata:
      labels:
        app: tbd-node-js-runner
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - tbd-node-js-runner
            topologyKey: topology.kubernetes.io/hostname
      containers:
        - name: tbd-node-js-runner
          image: tabidoo/nodejs-runner:latest
          ports:
          - containerPort: 
          env:
          - name: CONNECTION_STRING
            value: &quot;...&quot;
            ...
          imagePullPolicy: Always
      imagePullSecrets:
        - name: regcred
</code></pre>

<ul>
<li><p>It is due to incorrect topologyKey , It should be 'kubernetes.io/hostname' not 'topology.kubernetes.io/hostname' .</p>
</li>
<li><p>So it would be as following :</p>
</li>
</ul>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: tbd-node-js-runner
  namespace: default
spec:
  replicas: 2
  selector:
    matchLabels:
      app: tbd-node-js-runner
  template:
    metadata:
      labels:
        app: tbd-node-js-runner
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - tbd-node-js-runner
            topologyKey: &quot;kubernetes.io/hostname&quot;
      containers:
        - name: tbd-node-js-runner
          image: tabidoo/nodejs-runner:latest
</code></pre>
