What's the correct syntax or environment variables to specify podaffinity rule in a configmap

Hi ELK experts,

I have 3 node Elasticsearch(7.3.0) setup running on 3 separate hosts successfully. Now, I needed to scale down the hosts and run the same 3 nodes on 2 hosts. I am trying to use a configmap to set the podaffinity rule to use 'preferredDuringSchedulingIgnoredDuringExecution' with necessary labelselector. It was set to 'requriedDuringSchedulingIgnoredDuringExecution".

My deployment uses statefulset mechanism.

  1. Can I use configmap to change this configmap to change this setting and restart the pods?
  2. What's the correct syntax to specify the affinity or anti-affinity rule in configmap?

Current configuration in statefulset.

    affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - "elasticsearch-master"
            topologyKey: kubernetes.io/hostname

My configmap looks something like this, where I need to add the modified affinity rule.

apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-master-config
  namespace: stage
data:
  elasticsearch.yml: |
    cluster:
      name: elasticsearch
    
    node:
      master: true
      data: true
      ingest: true
    network.host: 0.0.0.0
    indices:
      query:
        bool:
          max_clause_count: 2000
    xpack:
      security:
        enabled: false
    http:
      max_header_size: "16kb"
      cors:
        enabled: true
        allow-origin: "*"
        allow-methods : "OPTIONS, HEAD, GET, POST, PUT, DELETE"
        allow-headers : "X-Requested-With,X-Auth-Token,Content-Type, Content-Length X-CSRF-Token"

Appreciate any help.

I solved it by redeploying the statefulset with the modified configuration.
As I understand, only few configuration can be changed in a statefulset when it's deployed and I think we can't use configmap to modify affinity configuration. Instead just delete the statefulset and recreate it.