6

I am fairly new to Kubernetes and was able to set up a workflow including ingress.

How can I specify which Deployments (not pods) go to a specific Node pool?

Also, do namespaces have any effect on the nodes as well?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
James
  • 305
  • 3
  • 12

2 Answers2

7

consult this link: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/

apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd

another option is to use affinity:

apiVersion: v1
kind: Pod
metadata:
  name: with-node-affinity
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: kubernetes.io/e2e-az-name
            operator: In
            values:
            - e2e-az1
            - e2e-az2
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: another-node-label-key
            operator: In
            values:
            - another-node-label-value
  containers:
  - name: with-node-affinity
    image: k8s.gcr.io/pause:2.0
4c74356b41
  • 69,186
  • 6
  • 100
  • 141
  • I am looking for assigning a deployment not a pod? Is there a way to do it for a deployment instead? – James Nov 23 '20 at 17:54
  • this makes no sense, deployments dont exist on nodes, they only exist in the api server – 4c74356b41 Nov 24 '20 at 05:22
  • @James, you can label the nodes accordingly with your pool name and then use the nodeAffinity in your deployment manifest to schedule your pod replicas into that pool . – acid_fuji Nov 24 '20 at 09:20
  • 2
    Ok I figured it out, you use the template in the deployment spec as a pod template then use that to set the nodes. This was also useful in figuring out how to set the node affinity – James Nov 25 '20 at 02:04
6

Nodes are independent of namespaces. You can specify node affinity rule in pod template you specify in deployment spec section. You can only assign pods to specific nodes, infact thats what deployment does creating pods so it makes sense to assign pods to nodes only.

slashpai
  • 1,141
  • 7
  • 12