Difference between revisions of "Kubernetes pod affinity and anti affinity"

From wikieduonline
Jump to navigation Jump to search
 
(18 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
   
 
   
 
  0/11 nodes are available: 1 [[Insufficient cpu]], 1 Too many pods, 10 nodes(s) didn't match Pod's node [[affinity]]/selector
 
  0/11 nodes are available: 1 [[Insufficient cpu]], 1 Too many pods, 10 nodes(s) didn't match Pod's node [[affinity]]/selector
  0/2 nodes are available: 1 Too many pods, 1 nodes(s) didn't match Pod's node [[affinity]]/selector
+
  0/2 nodes are available: 1 Too many pods, 1 nodes(s) [[didn't match Pod's node affinity/selector]]
 +
0/24 nodes are available: 0/24 [[nodes are available]]: 1 node(s) [[didn't match pod anti-affinity rules]], 1 node(s) [[were unschedulable]], 2 node(s) [[had taint]] {[[node.kubernetes.io/not-ready]]}, that the pod did not tolerate, 20 node(s) [[didn't match Pod's node affinity/selector]].
 +
 
 +
Too many pods, 1 nodes(s) [[didn't match Pod's node affinity/selector]]
 +
 
  
 
== Official examples ==
 
== Official examples ==
  
 
  [[apiVersion]]: v1
 
  [[apiVersion]]: v1
 
 
  [[kind:]] [[Pod]]
 
  [[kind:]] [[Pod]]
 
 
  [[metadata]]:
 
  [[metadata]]:
 
 
   name: [[with-node-affinity]]
 
   name: [[with-node-affinity]]
 
 
  spec:
 
  spec:
+
   [[affinity:]]  
   [[affinity]]:
 
 
 
     [[nodeAffinity]]:
 
     [[nodeAffinity]]:
 
 
       requiredDuringSchedulingIgnoredDuringExecution:
 
       requiredDuringSchedulingIgnoredDuringExecution:
 
 
         [[nodeSelectorTerms]]:
 
         [[nodeSelectorTerms]]:
 
 
         - [[matchExpressions]]:
 
         - [[matchExpressions]]:
 +
          - [[key:]] [[topology.kubernetes.io/zone]]
 +
            operator: In
 +
            values:
 +
            - antarctica-east1
 +
            - antarctica-west1
 +
      preferredDuringSchedulingIgnoredDuringExecution:
 +
      - weight: 1
 +
        [[preference:]]
 +
          [[matchExpressions]]:
 +
          - key: another-node-label-key
 +
            operator: In
 +
            [[values]]:
 +
            - another-node-label-value
 +
  [[containers]]:
 +
  - name: with-node-affinity
 +
    image: registry.k8s.io/pause:2.0
 +
apiVersion: v1
 +
kind: Pod
 +
metadata:
 +
  name: with-pod-affinity
 +
spec:
 +
  affinity:
 +
    podAffinity:
 +
      requiredDuringSchedulingIgnoredDuringExecution:
 +
      - labelSelector:
 +
          matchExpressions:
 
   
 
   
           - [[key:]] [[topology.kubernetes.io/zone]]
+
           - key: security
 
   
 
   
 
             operator: In
 
             operator: In
Line 35: Line 56:
 
             values:
 
             values:
 
   
 
   
            - antarctica-east1
+
            - S1
 +
 +
        topologyKey: topology.kubernetes.io/zone
 
   
 
   
            - antarctica-west1
+
    [[podAntiAffinity]]:
 
   
 
   
 
       preferredDuringSchedulingIgnoredDuringExecution:
 
       preferredDuringSchedulingIgnoredDuringExecution:
 
   
 
   
       - weight: 1
+
       - weight: 100
 +
 +
        podAffinityTerm:
 +
 +
          labelSelector:
 
   
 
   
        preference:
+
            matchExpressions:
 
   
 
   
          matchExpressions:
+
            - key: [[security]]
 
   
 
   
          - key: another-node-label-key
+
              operator: In
 
   
 
   
            operator: In
+
              values:
 
   
 
   
            values:
+
              - [[S2]]
 
   
 
   
            - another-node-label-value
+
          topologyKey: topology.kubernetes.io/zone
 
   
 
   
 
   containers:
 
   containers:
 
   
 
   
   - name: with-node-affinity
+
   - name: with-pod-affinity
 
   
 
   
     image: registry.k8s.io/pause:2.0
+
     [[image]]: registry.k8s.io/pause:2.0
 
 
 
 
<pre>
 
apiVersion: v1
 
 
 
kind: Pod
 
 
 
metadata:
 
 
 
  name: with-pod-affinity
 
 
 
spec:
 
 
 
  affinity:
 
 
 
    podAffinity:
 
 
 
      requiredDuringSchedulingIgnoredDuringExecution:
 
 
 
      - labelSelector:
 
 
 
          matchExpressions:
 
 
 
          - key: security
 
 
 
            operator: In
 
 
 
            values:
 
 
 
            - S1
 
 
 
        topologyKey: topology.kubernetes.io/zone
 
 
 
    podAntiAffinity:
 
 
 
      preferredDuringSchedulingIgnoredDuringExecution:
 
 
 
      - weight: 100
 
 
 
        podAffinityTerm:
 
 
 
          labelSelector:
 
 
 
            matchExpressions:
 
 
 
            - key: security
 
 
 
              operator: In
 
 
 
              values:
 
 
 
              - S2
 
 
 
          topologyKey: topology.kubernetes.io/zone
 
 
 
  containers:
 
 
 
  - name: with-pod-affinity
 
 
 
    image: registry.k8s.io/pause:2.0
 
</pre>
 
  
 
== Related ==
 
== Related ==
 
* [[Kubernetes Pod Topology Spread Constraints]]
 
* [[Kubernetes Pod Topology Spread Constraints]]
[[default-scheduler]]
+
* <code>[[default-scheduler]]</code>
 +
* [[Volume node affinity conflict]]
 +
* [[taints]], [[Node taints]]
 +
 
 +
== Activities ==
 +
* https://aws.amazon.com/about-aws/whats-new/2022/04/amazon-eks-karpenter-v0-9-0-pod-affinity/
  
 
== See also ==
 
== See also ==
 +
* {{K8s affinity}}
 
* {{K8s pods}}
 
* {{K8s pods}}
 +
* {{Karpenter}}
  
 
[[Category:K8s]]
 
[[Category:K8s]]

Latest revision as of 09:32, 25 January 2024

https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity


0/11 nodes are available: 1 Insufficient cpu, 1 Too many pods, 10 nodes(s) didn't match Pod's node affinity/selector
0/2 nodes are available: 1 Too many pods, 1 nodes(s) didn't match Pod's node affinity/selector
0/24 nodes are available: 0/24 nodes are available: 1 node(s) didn't match pod anti-affinity rules, 1 node(s) were unschedulable, 2 node(s) had taint {node.kubernetes.io/not-ready}, that the pod did not tolerate, 20 node(s) didn't match Pod's node affinity/selector. 

Too many pods, 1 nodes(s) didn't match Pod's node affinity/selector


Official examples[edit]

apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity: 
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: topology.kubernetes.io/zone
            operator: In
            values:
            - antarctica-east1
            - antarctica-west1
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  containers:
  - name: with-node-affinity
    image: registry.k8s.io/pause:2.0
apiVersion: v1
kind: Pod
metadata:
  name: with-pod-affinity
spec:
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:

          - key: security

            operator: In

            values:

           - S1

        topologyKey: topology.kubernetes.io/zone

    podAntiAffinity:

      preferredDuringSchedulingIgnoredDuringExecution:

      - weight: 100

       podAffinityTerm:

          labelSelector:

            matchExpressions:

            - key: security

              operator: In

              values:

              - S2

          topologyKey: topology.kubernetes.io/zone

  containers:

  - name: with-pod-affinity

    image: registry.k8s.io/pause:2.0

Related[edit]

Activities[edit]

See also[edit]

Advertising: