<p>I am using <code>Elastic Search(v7.6.1)</code> on a <code>Kubernetes(v1.19)</code> cluster.</p>
<p>The docs suggests to disable swapping:</p>
<p><a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html</a></p>
<p>My yaml:</p>
<pre><code>apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elastic-cluster-1
spec:
  version: 7.6.1
  image: docker.elastic.co/elasticsearch/elasticsearch:7.6.1
  nodeSets:
  - name: default
    count: 3
    config:
      node.master: true
      node.data: true
      node.ingest: true
    podTemplate:
      metadata:
        labels:
          # additional labels for pods
          type: elastic-master-node
      spec:
        nodeSelector:
          node-pool: &lt;NODE_POOL&gt;
        initContainers:
        # Increase linux map count to allow elastic to store large memory maps
        - name: sysctl
          securityContext:
            privileged: true
          command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']
        containers:
        - name: elasticsearch
          # specify resource limits and requests
          resources:
            limits:
              memory: 11.2Gi
            requests:
              cpu: 3200m
          env:
          - name: ES_JAVA_OPTS
            value: &quot;-Xms6g -Xmx6g&quot;
    # Request persistent data storage for pods
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 50Gi
        storageClassName: ssd
  - name: data
    count: 2
    config:
      node.master: false
      node.data: true
      node.ingest: true
    podTemplate:
      metadata:
        labels:
          # additional labels for pods
          type: elastic-data-node
      spec:
        nodeSelector:
          node-pool: &lt;NODE_POOL&gt;
        initContainers:
        # Increase linux map count to allow elastic to store large memory maps
        - name: sysctl
          securityContext:
            privileged: true
          command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']
        containers:
        - name: elasticsearch
          # specify resource limits and requests
          resources:
            limits:
              memory: 11.2Gi
            requests:
              cpu: 3200m
          env:
          - name: ES_JAVA_OPTS
            value: &quot;-Xms6g -Xmx6g&quot;
    # Request persistent data storage for pods
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 50Gi
        storageClassName: ssd
  # Google cloud storage credentials
  secureSettings:
  - secretName: &quot;gcs-credentials&quot;
  http:
    service:
      spec:
        # expose this cluster Service with a LoadBalancer
        type: LoadBalancer
    tls:
      certificate:
        secretName: elasticsearch-certificate
</code></pre>
<p>It's not clear to me how to change this yaml in order to disable swapping correctly. Changing each manually is not an option because in every restart the configuration will be lost.</p>
<p>How can I do this?</p>

Montoya
<p>First of all k8s cluster by default will have swap disabled, this is actually a <a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#before-you-begin" rel="nofollow noreferrer">mandatory requirement</a>. For most cases; especially cloud managed cluster which follows the requirement, you do not need to worry about swapping issue. Even for 1.22, enabling swap is only an alpha feature.</p>
<p>If for whatever reason you need to deal with this, you can consider setting <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration-memory.html#bootstrap-memory_lock" rel="nofollow noreferrer">bootstrap.memory_lock</a> to true.</p>
<pre><code>...
containers:
- name: elasticsearch
  env:
  - name: bootstrap.memory_lock
    value: &quot;true&quot;
...
</code></pre>
