1

My application consists of three different pods (Web, API and DB) and a PV and these pods will run in their own namespaces. These pods are deployed with a custom Helm Script.

So for example:

Namespace1: Web1, API1, DB1 and PV1
Namespace2: Web2, API2, DB2 and PV2
...
NampesaceN: WebN, APIN, DBN and PVN

I have multiple workers which can mount up to 16 PV's at the same time.

Now I want to schedule all coherent pods (from one namespace) on the same worker. I don't care what worker they are schedule on, but they should all run on the same worker where the PV is mounted. Is there some kind of namespace specific pod-affinity?

SO1992
  • 127
  • 1
  • 13
  • Why do they need to be on the same node? Kubernetes on its own knows to only schedule pods in places the matching PersistentVolume can be used (for example, if it's an AWS EBS-backed volume, not on a node in a different availability zone). – David Maze Feb 28 '21 at 12:02
  • I thought that pods needs to be scheduled on the same worker node as the PV in order to work correctly. Or can a PV be mounted on worker1, whereas a corresponding pod (accessing the PV) can be run on worker2? – SO1992 Feb 28 '21 at 18:01
  • 2
    The PV and the pod need to be on the same node, but the Kubernetes scheduler knows this and can handle it for you, moving one or the other as needed. (Assuming you're not using `hostPath:` storage.) – David Maze Feb 28 '21 at 18:22
  • Since all my pods use the PVC, it seems that I don't have to define something like pod affinity for my case. Thanks for your answer. – SO1992 Feb 28 '21 at 19:56
  • 1
    Scheduling new Pods is working. But when a Pod dies and restarts, Kubernetes tries to schedule it on a different node which has no access to the PV and it gives a "Multi attach error". – SO1992 Mar 09 '21 at 12:21

1 Answers1

1

I think you just need to ensure that if a type of Pod (Web or API etc.) is already scheduled on a Node then same type of Pod should not be scheduled again. And for that you need "Antiaffinity" and in that as well "Pod antiaffinity" instead of "Node antiaffinity".

Read this answer where I have explained in detail about it, along with official Kubernetes docs links to read more.

Have a look at this as well.

hagrawal7777
  • 14,103
  • 5
  • 40
  • 70