# Longhorn in GKE: Node Affinity

**URL:** <https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814>\
**Category:** SUSE Storage\
**Created:** [March 15, 2021, 5:18pm UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814 "2021-03-15T17:18:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![plechi](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/plechi/32/6892_2.png) [@plechi](https://forums.suse.com/u/plechi)\
**Post date:** [March 15, 2021, 5:18pm UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814/1 "2021-03-15T17:18:59Z")

</div>

Hi!  
I have a question concerning running Longhorn in GKE.

I already know that I cannot use the Google “Container Optimized OS” but need to run Ubuntu for Longhorn.

In my cluster, I have both Ubuntu and Container Optimized OS nodes and I used affinities to control which pods are scheduled on which node.

Can I use Longhorn in such an environment? Can I set the node affinity somewhere? If it works, is it correct that only the Ubuntu Nodes will be able to mount volumes managed by Longhorn?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![dko](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/dko/32/6950_2.png) [@dko](https://forums.suse.com/u/dko)\
**Post date:** [March 16, 2021, 4:40am UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814/2 "2021-03-16T04:40:36Z")

</div>

You can taint nodes for different purposes like non-longhron and longhorn workloads.

- Update the settings of `taint tolerance` in longhorn to tolerant the taint for longhorn workload
- Then, the longhorn workloads will be rescheduled to the tainted longhorn nodes

ref: [Longhorn | Documentation](https://longhorn.io/docs/1.1.0/advanced-resources/deploy/taint-toleration/)

---

<div class="post-metadata">

**Author:** ![PhanLe0110](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/phanle0110/32/7022_2.png) [@PhanLe0110](https://forums.suse.com/u/PhanLe0110)\
**Post date:** [March 18, 2021, 11:58pm UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814/3 "2021-03-18T23:58:03Z")

</div>

> If it works, is it correct that only the Ubuntu Nodes will be able to mount volumes managed by Longhorn?

Yes

---

<div class="post-metadata">

**Author:** ![weiyentan](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/weiyentan/32/6794_2.png) [@weiyentan](https://forums.suse.com/u/weiyentan)\
**Post date:** [April 9, 2021, 4:21am UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814/4 "2021-04-09T04:21:19Z")

</div>

@PhanLe0110, I am not quite sure about this one.

Taint and tolerations means that the node will only accept workload from certain pods.

Tolerations is on the pod and says that it will accept being put on a node but not being explicit.

For example lets say I have 5 nodes.  
ServerA  
ServerB  
ServerC  
ServerD  
ServerE

If I have a taint on ServerA and ServerB with something like storage=true:NoExecute ; storage=true:Noschedule. So as we expect this will not allow any pods to go on without having the toleration of storage=true:NoExecute ; storage=true:Noschedule.

So on the deployment we put on a toleration of:

storage=true:NoExecute  
storage=true:Noschedule

what this means is that when the pod is scheduled it WILL be accepted on ServerA and ServerB but it would will ALSO be accepted on ServerC,D,E if they happen to get scheduled on there.

To control where the pod gets ‘attracted’ to you have to use node affinity and this is something I can’t find on LongHorn

---

<div class="post-metadata">

**Author:** ![PhanLe0110](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/phanle0110/32/7022_2.png) [@PhanLe0110](https://forums.suse.com/u/PhanLe0110)\
**Post date:** [April 12, 2021, 8:14pm UTC](https://forums.suse.com/t/longhorn-in-gke-node-affinity/19814/5 "2021-04-12T20:14:14Z")

</div>

@weiyentan  
I see your use case! Thank you for the clarification.

Yeah, you are right. In order to solve this problem, Longhorn needs to allow users to specify `node selector` or `node affinity` so that Longhorn components only get deployed onto a specific group of nodes. We opt to go with `node selector` because it is simple and get the job done.

Another use case for this feature is that users have a cluster of both Linux nodes and Windows nodes. Users want to install Longhorn only on Linux nodes because Longhorn doesn’t work on Windows nodes.

We are working on this feature. The issue is tracked at [[FEATURE] Set tolerations and node selectors for dynamically provisioned Longhorn workloads · Issue #2199 · longhorn/longhorn · GitHub](https://github.com/longhorn/longhorn/issues/2199). If nothing changes, it will be scheduled to release in Longhorn v1.1.1
