Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubernetes node selector regex

Tags:

kubernetes

I'm trying to deploy pods on the nodes which have labels like es-node: data-1, es-node:data-2, es-node:data-3. I can use all the labels in pod's nodeaffinity spec but i just want to use single label entry as es-node:data-* so that it gets deployed on all the nodes. Is this even possible?

like image 200
karthik101 Avatar asked May 30 '26 21:05

karthik101


2 Answers

I don't think you can specify regular expressions on label selectors but you can just add an additional label, let's say es-node-type: data and put that as a label selector for your deployment or stateful set.

like image 82
Erez Rabih Avatar answered Jun 01 '26 20:06

Erez Rabih


Newer resources, such as Job, Deployment, ReplicaSet, and DaemonSet, support set-based requirements. I haven't tested this but you could probably use something like:

selector:
  matchExpressions:
    - {key: es-node, operator: In, values: [data-1, data-2, data-3]}

Source: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements

Openshift examples on using matchExpressions:

  • https://docs.openshift.com/container-platform/4.3/applications/deployments/what-deployments-are.html#deployments-repliasets_what-deployments-are
  • https://docs.openshift.com/container-platform/4.3/nodes/scheduling/nodes-scheduler-node-affinity.html
like image 23
Patrick McMahon Avatar answered Jun 01 '26 20:06

Patrick McMahon