# PodAffinityTermV1 Properties

- Package: [Aspire.Hosting.Kubernetes](/reference/api/csharp/aspire.hosting.kubernetes.md)
- Type: [PodAffinityTermV1](/reference/api/csharp/aspire.hosting.kubernetes/podaffinitytermv1.md)
- Kind: `Properties`
- Members: `6`

Represents a term used to define pod affinity/anti-affinity requirements in Kubernetes. The PodAffinityTermV1 specifies conditions such as label selectors, namespace selectors, and topology keys that determine the placement of pods in relation to other pods in a cluster.

## LabelSelector

- Name: `LabelSelector`
- Modifiers: `get; set`
- Returns: [LabelSelectorV1](/reference/api/csharp/aspire.hosting.kubernetes/labelselectorv1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs)

Gets or sets the label selector used to filter Kubernetes resources based on their labels. The label selector enables dynamic selection of a specific set of objects by matching labels or expressions that satisfy the requirements.

```csharp
public LabelSelectorV1 LabelSelector { get; set; }
```

## Remarks

The label selector may include the following components: - MatchLabels: A dictionary of key-value pairs where the labels of the resources must match exactly. - MatchExpressions: A collection of label selector requirements that define more advanced filtering conditions.

## MatchLabelKeys

- Name: `MatchLabelKeys`
- Modifiers: `get`
- Returns: `List<string>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs#L52)

A list of label keys that should match for the associated Kubernetes resource. This property specifies a set of labels that must be present and match among a group of resources when certain constraints, such as affinity or anti-affinity rules, are applied.

```csharp
public List<string> MatchLabelKeys { get; }
```

## Remarks

This property is intended to work in conjunction with label selectors to filter resources based on their labels. It helps define stricter conditions for selecting resources during workload scheduling and resource management in Kubernetes clusters.

## MismatchLabelKeys

- Name: `MismatchLabelKeys`
- Modifiers: `get`
- Returns: `List<string>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs#L66)

Represents a list of label keys that must NOT be matched by the target resources. This property is used as part of the label-based selection mechanism to exclude resources that have specific labels from being selected.

```csharp
public List<string> MismatchLabelKeys { get; }
```

## Remarks

MismatchLabelKeys is commonly used in conjunction with MatchLabelKeys and selectors like LabelSelector or NamespaceSelector to define precise inclusion and exclusion rules for Kubernetes resource selection. If a resource contains any of the labels specified in MismatchLabelKeys, it will not match the selector criteria.

## Namespaces

- Name: `Namespaces`
- Modifiers: `get`
- Returns: `List<string>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs#L80)

The Namespaces property represents a list of strings that define the specific namespaces within which the label selector or namespace selector should apply. This property is particularly useful when specifying criteria for selecting pods or other Kubernetes resources constrained to particular namespaces.

```csharp
public List<string> Namespaces { get; }
```

## Remarks

If the Namespaces property is null or empty, the selector will apply across all namespaces. This property enables fine-grained control over resource selection within the Kubernetes environment.

## NamespaceSelector

- Name: `NamespaceSelector`
- Modifiers: `get; set`
- Returns: [LabelSelectorV1](/reference/api/csharp/aspire.hosting.kubernetes/labelselectorv1.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs)

Gets or sets the namespace selector used to identify namespaces to which the label selector applies. This property specifies a label-based filter that restricts the namespaces considered by the associated label selector.

```csharp
public LabelSelectorV1 NamespaceSelector { get; set; }
```

## Remarks

The namespace selector is utilized to dynamically select namespaces based on their labels, allowing for more flexible and dynamic configurations. It operates in conjunction with label selectors to refine Kubernetes resource targeting.

## TopologyKey

- Name: `TopologyKey`
- Modifiers: `get; set`
- Returns: `string`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/5bd693ae1897dee5e2ce71c2cc08879c1c7eff51/src/Aspire.Hosting.Kubernetes/Resources/PodAffinityTermV1.cs)

Specifies the key for the node's topology on which matching should occur. The value of this property is used to categorize nodes in a cluster based on specific characteristics, such as region or zone. This is commonly used in Kubernetes for pod affinity and anti-affinity rules to determine how pods are scheduled across nodes.

```csharp
public string TopologyKey { get; set; }
```

## Remarks

The expected value must correspond to a label on the node that denotes the desired topology classification. It enables controlled distribution of pods across the nodes based on their topology attributes, ensuring improved resource utilization and failure isolation.
