kubernetes node selector regex

3/5/2019

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?

-- karthik101
kubernetes

2 Answers

3/23/2020

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:

-- Patrick McMahon
Source: StackOverflow

3/5/2019

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.

-- Erez Rabih
Source: StackOverflow