# Kubernetes: How To Ensure That Pod A Only Ends Up On Nodes Where Pod B Is Running

**URL:** <https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260>\
**Category:** General Discussions\
**Created:** [March 26, 2020, 5:16pm UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260 "2020-03-26T17:16:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Howard\_Roark](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/howard_roark/32/5845_2.png) [@Howard\_Roark](https://discuss.kubernetes.io/u/Howard_Roark)\
**Post date:** [March 26, 2020, 5:16pm UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260/1 "2020-03-26T17:16:40Z")

</div>

Asking for help? Comment out what you need so we can get more information to help you!

### Cluster information:

Kubernetes version: 1.15  
Cloud being used: AWS  
Host OS: Linux  
CNI and version: vpc-cni 1.5.5

### Question:

I have two use cases where teams only want Pod A to end up on a Node where Pod B is running. They often have many Copies of Pod B running on a Node, but they only want one copy of Pod A running on that same Node.

Currently they are using daemonsets to manage Pod A, which is not effective because then Pod A ends up on a lot of nodes where Pod B is not running. I would prefer not to restrict the nodes they can end up on with labels because that would limit the Node capacity for Pod B (ie- if we have 100 nodes and 20 are labeled, then Pod B’s possible capacity is only 20).

In short, how can I ensure that one copy of Pod A runs on any Node with at least one copy of Pod B running?

---

<div class="post-metadata">

**Author:** ![feloy](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/feloy/32/3669_2.png) [@feloy](https://discuss.kubernetes.io/u/feloy)\
**Post date:** [March 28, 2020, 7:21pm UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260/2 "2020-03-28T19:21:47Z")

</div>

I never experienced in your particular case, but you can probably use affinities: [Assigning Pods to Nodes - Kubernetes](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity)

---

<div class="post-metadata">

**Author:** ![Howard\_Roark](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/howard_roark/32/5845_2.png) [@Howard\_Roark](https://discuss.kubernetes.io/u/Howard_Roark)\
**Post date:** [March 28, 2020, 10:41pm UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260/3 "2020-03-28T22:41:45Z")

</div>

The reason for the use case is users are creating Daemonsets on a shared cluster. When there are big scaling events caused by other users, they end up having lots of pods scheduled on nodes for no reason. Really they are choosing to use a Daemonset with the idea that if any of _their_ pods are on a Node, then they want their daemonset pod to be on that node. So, I’m trying to come up with a solution to that where people’s Daemonsets only end up on nodes with their own pods.

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [March 29, 2020, 12:52am UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260/4 "2020-03-29T00:52:07Z")

</div>

I think you need custom logic. Either run a loop to label nodes like “has-user-a: yes” and use a DaemonSet or write your own DaemonSet-like thing to schedule the helper that you want on the nodes you want.

---

<div class="post-metadata">

**Author:** ![cocampbe](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/cocampbe/32/2748_2.png) [@cocampbe](https://discuss.kubernetes.io/u/cocampbe)\
**Post date:** [March 31, 2020, 3:56pm UTC](https://discuss.kubernetes.io/t/kubernetes-how-to-ensure-that-pod-a-only-ends-up-on-nodes-where-pod-b-is-running/10260/5 "2020-03-31T15:56:38Z")

</div>

Might be useful: [Inter-pod affinity and anti-affinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#inter-pod-affinity-and-anti-affinity)
