=====================================================================
Create label to run the buildon pod in a particular slave node using node affinity.
To get the slavenodename: kubectl get nodes
To Show create label for the k8s cluster node: kubectl get nodes --show-labels | grep slavelabelkubectl label nodes <slavenodename> thisnode=slavelabel
To Show label: kubectl get nodes --show-labels | grep slavelabel
...
=======================================================================
Example command using Node Affinity for ubuntu image:
kubectl run -i --tty buildon-<<commitid>>ubuntu --rm --image=devopsbasservice/buildonframework:buildon-v1.0 ubuntu --restart=Never --overrides='
...
"metadata": {
"name": "buildonslavenodeaffinityubuntutest"
},
"spec": {
"affinity": {
...
"key": "thisnode",
"operator": "In",
"values": [
"slavelabel"
]
...
}
}
}
}
}
'
===========================================================================
Enable Node Affinity for buildon pod. Change buildon.py "kubectl run" step as shown below.
===========================================================================
As-Is:
subprocess.Popen(['kubectl run '+ self.uid +' -i --tty --rm --restart=Never --image='+imagename+ ' --env="commitID='+self.uid+'" --env="branchName='+self.tuid+'" --env="gitURL='+self.httpurl+'" --env="KUBEMASTER='+self.host_ip+'" --env="UPLOADPORT='+self.upload_port+'" --env="scmServiceAccount='+self.scmServiceAccount+'"'], shell=True) |
To Be:
subprocess.Popen(['kubectl run '+ self.uid +' -i --tty --rm --restart=Never --image='+imagename+ ' --overrides='{ "apiVersion": "v1","kind":"Pod", "metadata": {"name": "buildonslave"},"spec": {"affinity": {"nodeAffinity": {"requiredDuringSchedulingIgnoredDuringExecution":{"nodeSelectorTerms": [ { "matchExpressions": [ { "key": "thisnode", "operator": "In", "values": [ "slavelabel"]}]}]}}}}}' --env="commitID='+self.uid+'" --env="branchName='+self.tuid+'" --env="gitURL='+self.httpurl+'" --env="KUBEMASTER='+self.host_ip+'" --env="UPLOADPORT='+self.upload_port+'" --env="scmServiceAccount='+self.scmServiceAccount+'"'], shell=True)