Re Scheduling pods from one node to another

6/23/2017

So, I am writing a custom auto-rescheduler for my clusters and I am using Python Client library to do so. As the rescheduler is still in proposal and nothing has been done for it, the only known way is to delete the pod from overused node and let the replication controller and scheduler take care of the rest (make a new pod and assign it to an appropriate node). What I want to know is can I use the client library to move the pods from one node to another without deleting the pod. Basically, I want to create a pod in an appropriate node first and then delete the pod in the over-used node. Is that possible?

-- vectar
kubernetes

1 Answer

6/23/2017

Using node label you can start the container in matching nodes. for this first you need set the node label and update the deployment file and apply it.

Here is the sample yml file I used for blue green deployment, see this help.

  1. web server running on node labeled web
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webserver-blue
spec:
  replicas: 2
  template:
    metadata:
      labels:
        type: webserver
        color: blue
    spec:
      containers:
      - image: nginx:1.12.0
        name: webserver-container
        ports:
        - containerPort: 80
          name: http-server
      nodeSelector:        
        svrtype: web
  1. set another node label as newweb and update and deployment with different name and node label the config.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webserver-green
spec:
  replicas: 2
  template:
    metadata:
      labels:
        type: webserver
        color: green
    spec:
      containers:
      - image: nginx:1.13.0
        name: webserver-container
        ports:
        - containerPort: 80
          name: http-server
      nodeSelector:        
        svrtype: newweb

After testing you can remove the old one. the issue here is you can direct the traffic to only one deployment at a time.

-- sfgroups
Source: StackOverflow