# Configuring podAntiAffinity for the connectware-agent Helm Chart

## Configuring podAntiAffinity

The `connectware-agent` Helm chart uses Kubernetes inter-pod anti-affinity to distribute configured agents across different Kubernetes nodes. The chart offers three modes of anti-affinity which you can choose with the `podAntiAffinity` value inside the agent’s entry in the `protocolMapperAgents` context of your values.yaml file:

| Mode             | Effect                                                                                                                            |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `soft` (default) | Will try to schedule agent pods on different Kubernetes nodes, but will schedule them on the same node if not possible otherwise. |
| `hard`           | Will schedule agent pods only on different nodes. If there are not enough matching nodes available, agents will not be scheduled. |
| `none`           | Will not add anti-affinity rules to the agents.                                                                                   |

**Example**

{% code lineNumbers="true" %}

```yaml
protocolMapperAgentDefaults:
    connectwareHost: connectware.cybus # adjust to actual hostname of Connectware
    podAntiAffinity: hard # agents will only be scheduled on different Kubernetes nodes
protocolMapperAgents:
    - name: bender-robots
    - name: welder-robots # will not be scheduled on the same Kubernetes node as bender-robots agent
```

{% endcode %}

## (Advanced) Overriding podAntiAffinity Options

If you want to configure very specific pod anti-affinity rules to match your Kubernetes cluster setup, you can use the values of the `podAntiAffinityOptions` section inside the agent’s entry in the `protocolMapperAgents` section of your values.yaml file.

Configuring podAntiAffinity Topology Key\
To change topology key used for the agent’s pod anti-affinity, specify the topology key in the `podAntiAffinityOptions.topologyKey` value inside the agent’s entry in the `protocolMapperAgents` context of your values.yaml file.

**Example**

{% code lineNumbers="true" %}

```yaml
protocolMapperAgentDefaults:
    connectwareHost: connectware.cybus # adjust to actual hostname of Connectware
    podAntiAffinity: hard # agents will only be scheduled on different availability zones
    podAntiAffinityOptions:
        topologyKey: topology.kubernetes.io/zone
protocolMapperAgents:
    - name: bender-robots
    - name: welder-robots # will not be scheduled on the same availability zone as bender-robots agent
```

{% endcode %}

### Configuring podAntiAffinity Match Expression

To change match expression used for the agent’s pod anti-affinity, specify the values `podAntiAffinityOptions.key`, `podAntiAffinityOptions.operator`, `podAntiAffinityOptions.value`, value inside the agents entry in the `protocolMapperAgents` section of your values.yaml file.

**Example**

{% code lineNumbers="true" %}

```yaml
protocolMapperAgentDefaults:
    connectwareHost: connectware.cybus # adjust to actual hostname of Connectware
    # Agents will not be scheduled on the same Kubernetes nodes as other agents.
    # This is also true for agents installed through other instances of this Helm chart.
    podAntiAffinity: hard
    podAntiAffinityOptions:
        key: app.kubernetes.io/component
        operator: In
        value: protocol-mapper-agent
protocolMapperAgents:
    - name: bender-robots
    - name: welder-robots # will not be scheduled on the same Kubernetes node as bender-robots agent
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cybus.io/1-10-2/documentation/agents/agents-in-kubernetes/configuring-agents-with-the-connectware-agent-helm-chart/configuring-podantiaffinity-for-the-connectware-agent-helm-chart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
