James
James

Reputation: 315

How to assign a Deployment to a specific Node Pool

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?

Upvotes: 7

Views: 19283

Answers (2)

slashpai
slashpai

Reputation: 1169

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.

Upvotes: 8

4c74356b41
4c74356b41

Reputation: 72151

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

Upvotes: 10

Related Questions