<p>Trying to test Pod Topology for the for the time. I chose to deploy it with a standard nginx deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  topologySpreadConstraints:
    - maxSkew: 1
      topologyKey: &quot;topology.kubernetes.io/zone&quot;
      whenUnsatisfiable: ScheduleAnyway
      labelSelector:
        matchLabels:
          app: nginx
    - maxSkew: 1
      topologyKey: &quot;kubernetes.io/hostname&quot;
      whenUnsatisfiable: ScheduleAnyway
      labelSelector:
        matchLabels:
          app: nginx
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
</code></pre>
<p>But deploying fails with the following error:</p>
<pre><code>➜  Dev kubectl apply -f nginx-test-deployment.yml                                                   
error: error validating &quot;nginx-test-deployment.yml&quot;: error validating data: ValidationError(Deployment.spec): unknown field &quot;topologySpreadConstraints&quot; in io.k8s.api.apps.v1.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>
<p>I am using EKS v1.21.5 and <code>topologySpreadConstraints</code> is available from v1.18.</p>
<pre><code>➜  ~ kubectl version
Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;21&quot;, GitVersion:&quot;v1.21.5&quot;, GitCommit:&quot;aea7bbadd2fc0cd689de94a54e5b7b758869d691&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-09-15T21:10:45Z&quot;, GoVersion:&quot;go1.16.8&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;21+&quot;, GitVersion:&quot;v1.21.5-eks-bc4871b&quot;, GitCommit:&quot;5236faf39f1b7a7dabea8df12726f25608131aa9&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-10-29T23:32:16Z&quot;, GoVersion:&quot;go1.16.8&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>

jrz
<p>It has to be defined in the POD's spec, read more about this field by running <code>kubectl explain Pod.spec.topologySpreadConstraints</code>.</p>
<p>Hence, move this configuration from <code>Deployment.spec.</code> to <code>Deployment.spec.template.spec.</code>.</p>
<p>For instance:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: &quot;topology.kubernetes.io/zone&quot;
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              app: nginx
        - maxSkew: 1
          topologyKey: &quot;kubernetes.io/hostname&quot;
          whenUnsatisfiable: ScheduleAnyway
          labelSelector:
            matchLabels:
              app: nginx
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
</code></pre>
