Kubernetes features - Deciding which pod to deploy on which worker

4/13/2018

I'm exploring kubernetes and I see that when the pod is created, the master automatically assigns it to some worker (I'm guessing randomly) in the cluster.

However, if the worker1 (low CPU specs) gets overloaded it extends the pod to worker2 (high-end CPU specs) eventually. I know that every time the pod will be overloaded and shifted to this high-end worker but still the master always initializes the pod on worker1.

Is there any feature which can allow me to configure the master such that it deploys the pods directly on the high-end worker rather than deploying it on a weak system and then shifting on to a better one?

-- Abhay Nayak
kubernetes

1 Answer

4/13/2018

There are lots of ways to do this, it really depends on your environment.

If you simply want to deploy your pod to a specific node, you can NodeSelectors. This assumes that the nodes in your cluster are labelled in a reasonable way, if you're in a cloud environment like AWS, you can simply specify the instance type:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    beta.kubernetes.io/instance-type: c4.xlarge

A more elaborate way of handling this is using Node Affinity but considering you just want to pin workloads to specific machines, this might be over the top.

One other thing to consider is why your pod is being moved. If you're not setting container resources for your pod, please consider doing that. As an example:

apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: db
    image: mysql
    env:
    - name: MYSQL_ROOT_PASSWORD
      value: "password"
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  - name: wp
    image: wordpress
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

Specifying the resources the container needs allows the scheduler to better decide where your pod should go based on its needed resources. If you specify container resources for your pod based on its max usage, the scheduler will realise that it should place the pod on the beefier node from the get go,

-- jaxxstorm
Source: StackOverflow