Is there a way to assign pods to the nodes in a particular nodegroup without labeling each node in the nodegroup?
E.g.:
Suppose I have two nodegroup NG1
and NG2
, and I have two apps A1
and A2
I want to assign pods of app A1
to nodegroup NG1
and pods of app A2
to nodegroup A2
. (I don't want to assign labels to each node in the nodegroup manually and then use nodeselector)
CodePudding user response:
You can use some of the default labels if those are coming and not same across the both Node pools
failure-domain.beta.kubernetes.io/zone
failure-domain.beta.kubernetes.io/region
beta.kubernetes.io/instance-type
beta.kubernetes.io/os
beta.kubernetes.io/arch
For example, if both of your Node pool running the different type of instances, you can use the beta.kubernetes.io/instance-type
Example
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: beta.kubernetes.io/instance-type
operator: In
values:
- Node Type
- Node Type
containers:
- name: with-node-affinity
image: registry.k8s.io/pause:2.0
You can also use the topology.kubernetes.io/zone
if zone if difference is there.
apiVersion: v1
kind: Pod
metadata:
name: with-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: topology.kubernetes.io/zone
operator: In
values:
- antarctica-east1
- antarctica-west1
containers:
- name: with-node-affinity
image: registry.k8s.io/pause:2.0
Update
If all the labels are the same you can try below command, which will list and label from a specific node group alpha.eksctl.io/nodegroup-name=ng-1
:
kubectl label nodes -l alpha.eksctl.io/nodegroup-name=ng-1 new-label=foo