Resource Requests and Limits in Kubernetes (Hands-on with Metrics Server) #40DaysOfKubernetes – Task

Resource Requests and Limits in Kubernetes (Hands-on with Metrics Server) #40DaysOfKubernetes – Task

1 2 7
calendar_today agoschedule3 min read
— Originally published at dev.to

What this is about

Today’s mission was simple on paper:
Teach Kubernetes how to handle memory politely.

In reality:
Kubernetes behaved like a strict landlord, and my containers learned consequences.

We explored:

memory requests (what you ask for)
memory limits (what you’re allowed to touch)
what happens when containers ignore both

Step 1: Creating a safe playground (namespace)

I started by isolating everything so I wouldn’t accidentally break the entire cluster (again):

kubectl create namespace mem-example

Image description

Step 2: Installing Metrics Server (the “fitness tracker” for pods)

Metrics Server is basically Kubernetes’ way of checking:

“Who is eating all the RAM?”

Installed it using the provided YAML.

Then… immediately learned Kubernetes loves drama.

Problem #1: Image pull failure 😭

My pod refused to start:


ImagePullBackOff

Translation:

“I tried to download your image… but the internet said no.”

Image description

So before I could even stress memory, Kubernetes was already stressed.

Then I sorted it out by deleting the metrics server and restarting it.

Image description

Step 3: A well-behaved container (for once)

Now I created a pod with rules:

Request: 100Mi (be reasonable)
Limit: 200Mi (don’t get greedy)
resources:
requests:

memory: "100Mi"

limits:

memory: "200Mi"

And then I told it:

“You may use 150Mi, but don’t embarrass me.”

Command:

kubectl apply -f memory-request-limit.yaml

Image description

What happened?

Shockingly… it behaved.

Checked usage:

kubectl top pod memory-demo -n mem-example

It used ~150Mi.
Image description

So Kubernetes basically said:

“You asked for 100Mi, but I’ll allow vibes up to 200Mi. Based off the yaml specifications”

Image description

Step 4: The “don’t exceed your limit” experiment 💀

Now I got ambitious (or careless).

Created another pod:

Request: 50Mi
Limit: 100Mi
Actual attempt: 250Mi (yes… I pushed it)

Image description

kubectl apply -f mem2.yaml

The result: Kubernetes said NO.

OOMKilled
Exit code 137

Image description

The container basically got:

“You exceeded your budget. Session terminated.”

And then it restarted… and died again… and again.

Image description

Image description

So yes, I successfully created a loop of failure.

Step 5: The “impossible request” experiment

Now I tried something unrealistic:

Request: 1000Gi memory
Limit: 1000Gi

Image description

Basically:

“I would like half the cluster please.”

Result:

Pod stayed in Pending
No node could even consider it

Image description

Image description

Image description

Kubernetes response:

“Be serious.”

What I learned (the real value)
Requests are not suggestions — they decide where your pod even goes
Limits are not suggestions — they decide how your pod dies
Kubernetes is very polite… until you exceed limits
OOMKilled is just Kubernetes saying “enough”
If your request is unrealistic, your pod doesn’t crash — it just never gets invited in

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Day 17/40 — Kubernetes Autoscaling: HPA vs VPA Explained With Hands-On Practice

AYANFE - Jul 1

Learn AWS for Free Hands On Without Getting Charged

Ijay - Feb 24

Split-Brain: Analyst-Grade Reasoning Without Raw Transactions on the Server

Pocket Portfolio - Apr 8

Deploying Backstage on Kubernetes with the Helm Chart: The Infrastructure-First Guide

JIMOH SODIQ - Apr 17

Hearth: scale-to-zero LLM serving on Kubernetes — and you can hack on it without a GPU

kube-gopher - Jun 11
chevron_left
187 Points10 Badges
Abuja,Nigeria.linktr.ee/oye_bobs
3Posts
1Comments
1Connections
A gentleman with a rough edge.

Related Jobs

View all jobs →

Commenters (This Week)

2 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!