Kubernetes - Specify Instance Using nodeSelector

3/13/2017

Is there a way to specify a specific instance instead of a pool of instances using nodeSelector in Kubernetes?

If not, what would be the best way to provision a Redis Cluster with each node having at least 30GB of memory. Can this be accomplished using the resources attribute?

By the way, I'm currently creating 6 pools with 1 instance in each and then specifying that in the config but it doesn't look right:

nodeSelector:
  cloud.google.com/gke-nodepool: my-pool-1
-- Artem Kalinchuk
google-cloud-platform
kubernetes

2 Answers

3/14/2017

You shouldn't need to use nodeSelector at all in this case. The idea is that you provide your requirements and let the scheduler decide which nodes to use.

If each of you Pods actually need 30GB of memory then specify a resource request in your Pod(template) for the container that needs it:

...
spec:
  containers:
  - ...    
    resources:
      requests:
        memory: "30Gi"

Now if a Node has more than 60GB RAM it may have 2 of your Pods scheduled. If for some reason you also need to make sure that each Node runs at most 1 your Pods of this type you can use specify an inter-pod anti-affinity in your Pod(template):

...
metadata:
  name: with-pod-affinity
  annotations: >
    {
      "podAntiAffinity": {
        "requiredDuringSchedulingIgnoredDuringExecution": [
          {
            "topologyKey": "kubernetes.io/hostname"
          }
        ]
      }
    }
spec:
  ...
-- Janos Lenart
Source: StackOverflow

3/13/2017

The kubelet should automatically add a label for the hostname, using kubernetes.io/hostname.

With that in mind, you can pin a pod to a specific host using:

nodeSelector:
  kubernetes.io/hostname: "<hostname>"

I would question if this is a good idea, however.

-- jaxxstorm
Source: StackOverflow