0
0
Kubernetesdevops~30 mins

Limit ranges for defaults in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Limit Ranges for Defaults in Kubernetes
📖 Scenario: You are managing a Kubernetes cluster where developers deploy their applications. To ensure fair resource usage and avoid accidental overconsumption, you want to set default resource limits and requests for all pods in a namespace.
🎯 Goal: Create a Kubernetes LimitRange resource that sets default CPU and memory requests and limits for containers in a namespace.
📋 What You'll Learn
Create a LimitRange YAML manifest named limitrange.yaml
Set default CPU request to 100m and default memory request to 200Mi
Set default CPU limit to 500m and default memory limit to 500Mi
Apply the LimitRange to the development namespace
💡 Why This Matters
🌍 Real World
In real Kubernetes clusters, setting default resource limits helps avoid resource starvation and ensures fair sharing among applications.
💼 Career
DevOps engineers and cluster administrators use LimitRanges to enforce resource policies and maintain cluster stability.
Progress0 / 4 steps
1
Create the basic LimitRange YAML skeleton
Create a YAML file named limitrange.yaml with the following top-level keys: apiVersion set to v1, kind set to LimitRange, and metadata with name set to resource-limits and namespace set to development.
Kubernetes
Need a hint?

Use the apiVersion, kind, and metadata fields to define the LimitRange resource.

2
Add the spec and limits section
Add a spec section with a limits list containing one item. This item should have type set to Container.
Kubernetes
Need a hint?

The spec section defines the rules. The limits list holds the limit definitions.

3
Set default CPU and memory requests and limits
Inside the limits item, add defaultRequest with cpu: 100m and memory: 200Mi, and default with cpu: 500m and memory: 500Mi.
Kubernetes
Need a hint?

Use defaultRequest for default resource requests and default for default limits.

4
Apply the LimitRange to the development namespace and verify
Run the command kubectl apply -f limitrange.yaml to create the LimitRange in the development namespace. Then run kubectl get limitrange resource-limits -n development -o yaml to display the applied LimitRange.
Kubernetes
Need a hint?

Use kubectl apply -f limitrange.yaml to apply and kubectl get limitrange resource-limits -n development -o yaml to verify.