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, 2019 in Kubernetes by Namik
• 1,230 points
19,808 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, 2019 by Sirajul
• 59,230 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, 2019 in Kubernetes by Sirajul
• 59,230 points
3,707 views
0 votes
1 answer

What is Ingress ? Is it something that runs as a pod or on a pod?

An ingress is an object that holds ...READ MORE

answered Jul 19, 2019 in Kubernetes by Sirajul
• 59,230 points
1,887 views
0 votes
1 answer

What is Scaling in Kubernetes and how would you enable it?

On Google Compute Engine (GCE) and Google Container Engine (GKE) (and ...READ MORE

answered Feb 11, 2020 in Kubernetes by anonymous
• 59,230 points
1,039 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17, 2019 in Others by anonymous
15,424 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,350 points

reshown Apr 12, 2019 by Kalgi 7,042 views
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, 2019 in Kubernetes by Sirajul
• 59,230 points
967 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, 2019 in Kubernetes by Sirajul
• 59,230 points
1,315 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP