Does the Pod Affinity/Anti Affinity apply to DaemonSet pods

1,454 views
Skip to first unread message

krma...@gmail.com

unread,
Feb 12, 2017, 3:26:36 AM2/12/17
to Kubernetes developer/contributor discussion
After the node have been selected using node affinity, can you still use pod affinity/anti affinity to further restrict daemon set pod placement ?

David Oppenheimer

unread,
Feb 12, 2017, 3:43:12 AM2/12/17
to krma...@gmail.com, Kubernetes user discussion and Q&A
[+kubernetes-users; kubernetes-dev to bcc]

No, and actually affinity doesn't work with DaemonSet right now either. The problem is that DaemonSet does its own scheduling and doesn't yet share all of the scheduler code. 

The only affinity-related constraint that works with DaemonSet right now is nodeSelector (a field of podSpec).


On Sun, Feb 12, 2017 at 12:26 AM, <krma...@gmail.com> wrote:
After the node have been selected using node affinity, can you still use pod affinity/anti affinity to further restrict daemon set pod placement ?

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/99c8fc8c-ff2e-499c-af68-3ab21c62a1ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

krma...@gmail.com

unread,
Feb 12, 2017, 4:11:00 AM2/12/17
to Kubernetes developer/contributor discussion, krma...@gmail.com, kubernet...@googlegroups.com
Hi David
Thanks. You mean both nodeSelector and node affinity right. As per this doc https://kubernetes.io/docs/admin/daemons/#running-pods-on-only-some-nodes, both nodeSelector and node affinity work.

But yeah my questions was about pod affinity/anti affinity which you are saying doesnt work with DS. I am guessing it doesn't even make sense to have pod affinity/anti affinity work with Daemon Sets since then daemon set making a pod of certain kind per node definition would no longer be true ?

-Mayank


On Sunday, February 12, 2017 at 12:43:12 AM UTC-8, David Oppenheimer wrote:
[+kubernetes-users; kubernetes-dev to bcc]

No, and actually affinity doesn't work with DaemonSet right now either. The problem is that DaemonSet does its own scheduling and doesn't yet share all of the scheduler code. 

The only affinity-related constraint that works with DaemonSet right now is nodeSelector (a field of podSpec).

On Sun, Feb 12, 2017 at 12:26 AM, <krma...@gmail.com> wrote:
After the node have been selected using node affinity, can you still use pod affinity/anti affinity to further restrict daemon set pod placement ?

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.

David Oppenheimer

unread,
Feb 12, 2017, 4:55:42 AM2/12/17
to krma...@gmail.com, Kubernetes user discussion and Q&A
[moving kubernetes-dev back to bcc]


On Sun, Feb 12, 2017 at 1:11 AM, <krma...@gmail.com> wrote:
Hi David
Thanks. You mean both nodeSelector and node affinity right. As per this doc https://kubernetes.io/docs/admin/daemons/#running-pods-on-only-some-nodes, both nodeSelector and node affinity work.

I believe that documentation is wrong. More specifically, the spec.template.spec.nodeSelector part is correct, but the .spec.template.metadata.annotations part is wrong (not yet supported for DaemonSet). The predicate functions respected by DaemonSet are only the ones listed here: https://github.com/kubernetes/kubernetes/blob/4ed86f5d4649ff9e612ad945b38ce9db147daaef/plugin/pkg/scheduler/algorithm/predicates/predicates.go#L840

 

But yeah my questions was about pod affinity/anti affinity which you are saying doesnt work with DS. I am guessing it doesn't even make sense to have pod affinity/anti affinity work with Daemon Sets since then daemon set making a pod of certain kind per node definition would no longer be true ?

I guess you could use pod anti-affinity to say something like "one daemon per rack" but I agree that in general the uses are very limited.
 

-Mayank


On Sunday, February 12, 2017 at 12:43:12 AM UTC-8, David Oppenheimer wrote:
[+kubernetes-users; kubernetes-dev to bcc]

No, and actually affinity doesn't work with DaemonSet right now either. The problem is that DaemonSet does its own scheduling and doesn't yet share all of the scheduler code. 

The only affinity-related constraint that works with DaemonSet right now is nodeSelector (a field of podSpec).


On Sun, Feb 12, 2017 at 12:26 AM, <krma...@gmail.com> wrote:
After the node have been selected using node affinity, can you still use pod affinity/anti affinity to further restrict daemon set pod placement ?

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/99c8fc8c-ff2e-499c-af68-3ab21c62a1ad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/72b0b4ca-b6cc-40a6-b61a-5b0582d896a4%40googlegroups.com.

Łukasz Oleś

unread,
Feb 15, 2017, 7:43:30 AM2/15/17
to Kubernetes developer/contributor discussion, krma...@gmail.com, kubernet...@googlegroups.com


On Sunday, February 12, 2017 at 10:55:42 AM UTC+1, David Oppenheimer wrote:
[moving kubernetes-dev back to bcc]


On Sun, Feb 12, 2017 at 1:11 AM, <krma...@gmail.com> wrote:
Hi David
Thanks. You mean both nodeSelector and node affinity right. As per this doc https://kubernetes.io/docs/admin/daemons/#running-pods-on-only-some-nodes, both nodeSelector and node affinity work.

I believe that documentation is wrong. More specifically, the spec.template.spec.nodeSelector part is correct, but the .spec.template.metadata.annotations part is wrong (not yet supported for DaemonSet). The predicate functions respected by DaemonSet are only the ones listed here: https://github.com/kubernetes/kubernetes/blob/4ed86f5d4649ff9e612ad945b38ce9db147daaef/plugin/pkg/scheduler/algorithm/predicates/predicates.go#L840

so DaemonSet also supports node affinity.

When I was changing DaemonSets to use GeneralPredicates I also added a unit test to check node affinity: https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/daemon/daemoncontroller_test.go#L608 

Regards

David Oppenheimer

unread,
Feb 16, 2017, 1:47:29 AM2/16/17
to Łukasz Oleś, Kubernetes developer/contributor discussion, krma...@gmail.com, Kubernetes user discussion and Q&A
Ah, you're right, thanks for the correction.


--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.

krma...@gmail.com

unread,
Feb 16, 2017, 10:02:33 PM2/16/17
to Kubernetes developer/contributor discussion, lukas...@gmail.com, krma...@gmail.com, kubernet...@googlegroups.com
thanks all of you


On Wednesday, February 15, 2017 at 10:47:29 PM UTC-8, David Oppenheimer wrote:
Ah, you're right, thanks for the correction.

On Wed, Feb 15, 2017 at 4:43 AM, Łukasz Oleś <lukas...@gmail.com> wrote:


On Sunday, February 12, 2017 at 10:55:42 AM UTC+1, David Oppenheimer wrote:
[moving kubernetes-dev back to bcc]


On Sun, Feb 12, 2017 at 1:11 AM, <krma...@gmail.com> wrote:
Hi David
Thanks. You mean both nodeSelector and node affinity right. As per this doc https://kubernetes.io/docs/admin/daemons/#running-pods-on-only-some-nodes, both nodeSelector and node affinity work.

I believe that documentation is wrong. More specifically, the spec.template.spec.nodeSelector part is correct, but the .spec.template.metadata.annotations part is wrong (not yet supported for DaemonSet). The predicate functions respected by DaemonSet are only the ones listed here: https://github.com/kubernetes/kubernetes/blob/4ed86f5d4649ff9e612ad945b38ce9db147daaef/plugin/pkg/scheduler/algorithm/predicates/predicates.go#L840

so DaemonSet also supports node affinity.

When I was changing DaemonSets to use GeneralPredicates I also added a unit test to check node affinity: https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/daemon/daemoncontroller_test.go#L608 

Regards

--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages