Resource Restrictions in K8s
-
Generally we have two kinds of controls
-
requests: This represents minimum limit required
-
limits: This represents maximum limit
- Resource Types
-
CPU: 1000m => 1 cpu
-
Memory
-
Lets create a pod with container which requires
- minimum => 0.1 cpu and 64MB RAM
- max => 0.5 cpu and 256MB RAM
apiVersion: v1
kind: Pod
metadata:
name: ex-1
spec:
containers:
- name: web
image: nginx
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 500m
memory: 256Mi
- requests and limits impact Quality of Service in k8s: Prompt
Give me tabular representation of different QOS by k8s with different possibilities of request and limits and what they mean
Also show me impact of QoS under resource pressure by example
- Note: Ensure when we write a pod spec at a bare minimum we make it burstable and define probes (Readiness and liveness)
Labels
- A label is a key value pair which is used in k8s for querying (selectors)

- We can apply labels in manifest from metadata section
- We can also apply labels using kubectl label command
-
Refer Here
-
Selectors are of two types Refer Here
- Equality (equal or not equal)
- Set (in, not in, defined, undefined)
-
In k8s we spoke about desired state
- The desired state of pod is ensure containers are in running state
- In Reality i might need 3 instances of pod and we might need to handle rolling out new versions, For this k8s has controller objects
- Controller objects control pods
K8s Controller Objects
- Replica Sets or ReplicationControllers
- Deployments
- DaemonSets
- Jobs or CronJobs
- StatefulSet

ReplicaSets
- This controller creates multiple pod instances and ensure the count is maintained.
- When we write Replica set we do two things
- we need to tell which pods belong to replica set (label selectors)
- If the pod is not running to create a pod we need pod specification. (template)
- Lets create a replicaset which requires 3 replicas of nginx containers with label app=web
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: ex-1
labels:
purpose: learning
spec:
minReadySeconds: 10
replicas: 2
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
version: v1
spec:
containers:
- name: web
image: httpd
resources:
limits:
memory: 200Mi
cpu: 500m