kubernetes: Daemonset doesn't properly respect nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms

What happened:

I create DaemonSet in the Kubernetes v1.17.2 cluster, i use NodeAffinity make pods only running on the node that have specified labels, but it not work. I get the pod information and the affinity have been override.

What you expected to happen:

DaemonSet node affinity works.

How to reproduce it (as minimally and precisely as possible):

  1. write a DaemonSet
  2. add node affinity like below:
affinity:
    nodeAffinity: 
        requiredDuringSchedulingIgnoredDuringExecution: 
        nodeSelectorTerms: 
        - matchExpressions: 
            - key: app
            operator: In
            values: 
            - fluent
  1. kubectl get pod -oyaml. The pod affinity become:
nodeAffinity:
  requiredDuringSchedulingIgnoredDuringExecution:
    nodeSelectorTerms:
    - matchFields:
      - key: metadata.name
        operator: In
        values:
        - worker1

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):

v1.17.2

  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

issue still exists on Kubernetes v1.28

similar issue link: https://github.com/kubernetes/kubernetes/issues/104984

/reopen This is still an issue. The daemonset controller just straight up overrides nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms of a pod:

The observeable behavior is that it first creates pods for nodes that have a non-matching selector but without the selector in the pod object and then later on deletes it. Depending on timing, that means that the pod might run temporarily which caused an incident for us, as it is very unexpected.

/retitle Daemonset doesn’t properly respect nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.NodeSelectorTerms /sig apps