What is pod affinity and node affinity?

0 votes
Hey i'm a newbie to Kubernetes. Could somebody help me in understanding Pod affinity and Node affinity? Thanks in advance.
Jul 17 in Kubernetes by Namik
• 1,200 points
22 views

1 answer to this question.

0 votes
  • Node Affinity ensures that pods are hosted on particular nodes.

  • Pod Affinity ensures two pods to be co-located in a single node.

Node 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

Pod Affinity

apiVersion: v1
kind: Pod
metadata:
name: with-pod-affinity
spec:
  affinity:
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
          - key: security
            operator: In
            values:
            - S1

The pod affinity rule says that the pod can be scheduled to a node only if that node is in the same zone as at least one already-running pod that has a label with key “security” and value “S1”

For a better understanding refer to: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/

answered Jul 17 by Sirajul
• 17,910 points

Related Questions In Kubernetes

0 votes
1 answer
0 votes
1 answer

What is the difference between config map and secret in kubernetes?

Config maps ideally stores application configuration in ...READ MORE

answered Jul 17 in Kubernetes by Sirajul
• 17,910 points
44 views
0 votes
1 answer
0 votes
1 answer

What is unknown user client in kubernetes?

I think your Legacy Authorisation has been ...READ MORE

answered Sep 12, 2018 in Kubernetes by DareDev
• 6,810 points
44 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
1,601 views
+3 votes
1 answer
0 votes
1 answer

What is pod security policy and why is it important?

In Kubernetes, Pod Security Policies consists of ...READ MORE

answered Jul 17 in Kubernetes by Sirajul
• 17,910 points
12 views
0 votes
1 answer

Is it possible to force the pod to run on a specific node?

By default, anti-affinity is not attempted by ...READ MORE

answered Jul 15 in Kubernetes by Sirajul
• 17,910 points
32 views