podAffinity Example

An example of affinity and podAffinity settings can be seen below. This also requires a particular label to be matched when the Pod starts, but not required if the label is later removed.

spec:
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - S1

The Pod can be scheduled on a node running a Pod with a key label of security and a value of S1. If this requirement is not met, the Pod will remain in a Pending state.

Last updated