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

**URL:** <https://discuss.elastic.co/t/whats-the-correct-syntax-or-environment-variables-to-specify-podaffinity-rule-in-a-configmap/239002>\
**Category:** Elastic Cloud on Kubernetes (ECK)\
**Created:** [June 28, 2020, 11:10am UTC](https://discuss.elastic.co/t/whats-the-correct-syntax-or-environment-variables-to-specify-podaffinity-rule-in-a-configmap/239002 "2020-06-28T11:10:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkmohapatra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkmohapatra/32/54250_2.png) [@rkmohapatra](https://discuss.elastic.co/u/rkmohapatra)\
**Post date:** [June 28, 2020, 11:10am UTC](https://discuss.elastic.co/t/whats-the-correct-syntax-or-environment-variables-to-specify-podaffinity-rule-in-a-configmap/239002/1 "2020-06-28T11:10:32Z")

</div>

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.

```auto
    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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![rkmohapatra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkmohapatra/32/54250_2.png) [@rkmohapatra](https://discuss.elastic.co/u/rkmohapatra)\
**Post date:** [June 29, 2020, 11:32am UTC](https://discuss.elastic.co/t/whats-the-correct-syntax-or-environment-variables-to-specify-podaffinity-rule-in-a-configmap/239002/2 "2020-06-29T11:32:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 4, 2022, 8:04am UTC](https://discuss.elastic.co/t/whats-the-correct-syntax-or-environment-variables-to-specify-podaffinity-rule-in-a-configmap/239002/3 "2022-11-04T08:04:12Z")

</div>


