I am creating an autonomous rescheduler that is capable of rescheduling Pods on the go based on resource usage, network metrics and so on. My Kubernetes cluster currently only has 5 deployments as a test setup each with only a single instance of a Pod (replicas: 1). I am able to generate a new scheduling in my system and apply that to the cluster by executing the following patch;
kubectl patch deployment fake-microservice-1 -p "{\"spec\":{\"template\":{\"spec\":{\"nodeSelector\":{\"kubernetes.io/hostname\":\"node1\"}}}}}"
This patch successfully moves the Pod in the fake-microservice-1
deployment to node1
.
The next thing I want to implement is, in case there are multiple replicas of a Pod in a deployment, that I am able to move each individual Pod within the deployment to a specific node. For example, assume the fake-microservice-1
deployment to have 2 replicas (2 Pods). How can I, for example, move one of the Pods to node1
and the other to node4
.
I have tried to patch a single Pod's nodeAffinity
but this isn't possible because Kubernetes doesn't allow updates to this value when a Pod is running.
Is there a way to move individual Pods within a deployment to a specific node, either by patching some values, adding labels or through other means?
Not that it matters too much but all of this is being developed in Go.