Kubernetes Pod Scheduling with Affinity
Key Points
- Kubernetes automatically schedules pods across worker (virtual or physical) nodes using its built‑in scheduler to balance resources.
- Each pod is visualized by a “drone” that changes color to match the node it’s placed on, illustrating pod‑to‑node assignment.
- Affinity and anti‑affinity policies let you control pod placement; an anti‑affinity rule can prevent multiple instances of the same app from running on the same node.
- When scaling from one to three replicas with an anti‑affinity rule and three nodes, Kubernetes distributes each pod to a different node as intended.
- Adding a fourth replica with only three nodes causes the extra pod to remain pending, showing that hard anti‑affinity can block scheduling unless you use softer rules that allow fallback to default placement.
Full Transcript
# Kubernetes Pod Scheduling with Affinity **Source:** [https://www.youtube.com/watch?v=pAO7300nluc](https://www.youtube.com/watch?v=pAO7300nluc) **Duration:** 00:02:57 ## Summary - Kubernetes automatically schedules pods across worker (virtual or physical) nodes using its built‑in scheduler to balance resources. - Each pod is visualized by a “drone” that changes color to match the node it’s placed on, illustrating pod‑to‑node assignment. - Affinity and anti‑affinity policies let you control pod placement; an anti‑affinity rule can prevent multiple instances of the same app from running on the same node. - When scaling from one to three replicas with an anti‑affinity rule and three nodes, Kubernetes distributes each pod to a different node as intended. - Adding a fourth replica with only three nodes causes the extra pod to remain pending, showing that hard anti‑affinity can block scheduling unless you use softer rules that allow fallback to default placement. ## Sections - [00:00:00](https://www.youtube.com/watch?v=pAO7300nluc&t=0s) **Visualizing Kubernetes Pod Scheduling** - The segment explains how Kubernetes’s scheduler assigns pods to worker nodes, uses anti‑affinity rules to keep replicas off the same node, and demonstrates scaling replicas with colored lights and drone icons representing nodes and pods. ## Full Transcript
[Music]
kubernetes makes an application running
in a cluster both available and
responsive by effectively scheduling the
use of infrastructure let's talk
specifically about what makes up our
kubernetes cluster as a reminder the
container for our online travel
application is encapsulated in a pod and
a drone is associated with each pod
kubernetes deploys now worker nodes are
where our application containers
actually run to demonstrate how pods
interact with worker nodes will use
these three lights each light represents
a worker node first keep in mind that a
worker node can be either a virtual or
physical machine kubernetes manages this
underlying infrastructure by default a
scheduler automatically distributes pods
across worker nodes to balance the
available resources appropriately
kubernetes allows you to define affinity
and anti affinity policies to allow a
simple way to assign pods to nodes to
see that in action we'll create a policy
that tells kubernetes to not run
multiple instances of my application on
the same note we'll associate our three
kubernetes worker nodes with the colors
green red and blue when kubernetes
creates a pod and assigns it to a worker
node the drone will change its color to
match the light box and then move to
hover above it we can apply our
deployment with one replica
[Music]
as expected one drone takes off and
moves to the worker node it was assigned
let's scale to three all we have to do
is change our deployment to have three
replicas
[Music]
because we had an anti affinity rule in
place each pod was scheduled to a
different worker node what happens if we
scale to four when we only have three
worker nodes let's find out
[Music]
looks like our fourth drone is a bit
lost
that's because kubernetes is not able to
schedule this pod and it's stuck in a
pending state it's important to
understand and apply your affinity
policies carefully kubernetes allows for
both hard and soft affinity he should
rely and creating soft affinity rules if
you want kubernetes to fall back to its
default scheduling when it's not able to
meet your affinity rules
you