Create label to run the buildon pod in a particular slave node using node affinity.
...
===========================================================================
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": "labelnode1", "operator": "In", "values": [ "nodelabel"]}]}]}}}}}' --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)
Reference: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/