Reputation: 1719
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?
Upvotes: 9
Views: 18304
Reputation: 11
Recently, I faced the same, when I implemented a lifecycle policy on GKE NodePools with a policy to Create_Before_Destroy using Terraform.
This solved the problem that I want to solve. But, landed me with a new project related to NodeSelector.
Every time a node pool creates after the terraform lifecycle policy implementation, node-pool-**** name used to have 4 junk characters appended as its suffix all the time.
This will be a tough challenge if you hardcode the values of the node pool on selectors, as the node pool names keep on changing.
Here are a few of the ways that you can solve this.
RFC Expression Online Maker: https://www.regextester.com/103452
You can use the below nodeSelector in your Kubernetes resources
nodeSelector: node_pool: stack-overflow
This is the easiet fix.
Instead of using the above key, if you use the cloud provided label, nodeSelector: cloud.google.com/gke-nodepool: stack-overflow-1234
Value would be based on the newly created nodepool name, which you can build using the above provided RFC Rex-Ex Maker.
Thanks
Upvotes: 0
Reputation: 414
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]}
Openshift examples on using matchExpressions
:
Upvotes: 1
Reputation: 15788
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.
Upvotes: 2