How to assign a Deployment to a specific Node Pool

11/23/2020

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?

-- James
azure-aks
deployment
kubernetes

2 Answers

11/23/2020

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
Source: StackOverflow

11/24/2020

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
Source: StackOverflow