Goal: fix nosql Deployment in haddock so the container stops OOM’ing by setting:
You must do this on the correct host.
0) Connect to the correct host
ssh ckad00032
1) Confirm the failing Deployment / Pods
kubectl -n haddock get deploy nosql
kubectl -n haddock get pods -l app=nosql 2>/dev/null || kubectl -n haddock get pods
If pods are crashing, check why (you’ll likely see OOMKilled):
kubectl -n haddock describe pod
2) Find the maximum memory constraint set for the haddock namespace
In CKAD labs, this is commonly enforced by a LimitRange (max memory per container). Sometimes it can also be a ResourceQuota.
2A) Check LimitRange (most likely)
kubectl -n haddock get limitrange
kubectl -n haddock get limitrange -o yaml
Extract the max memory value quickly:
MAX_MEM=$(kubectl -n haddock get limitrange -o jsonpath='{.items[0].spec.limits[0].max.memory}')
echo "Namespace max memory constraint: $MAX_MEM"
2B) If no LimitRange exists, check ResourceQuota
kubectl -n haddock get resourcequota
kubectl -n haddock describe resourcequota
If quota is used, you’re looking for something like limits.memory (but the question wording “maximum memory constraint” usually points to LimitRange max.memory).
3) Compute “half of the max memory constraint”
Run this small snippet to compute HALF in Mi (handles Mi and Gi):
HALF_MEM=$(python3 - <<'PY'
import os, re
q = os.environ.get("MAX_MEM","").strip()
m = re.fullmatch(r"(\d+)(Mi|Gi)", q)
if not m:
raise SystemExit(f"Cannot parse MAX_MEM='{q}'. Expected like 512Mi or 1Gi.")
val = int(m.group(1))
unit = m.group(2)
# convert to Mi
mi = val if unit == "Mi" else val * 1024
half_mi = mi // 2
print(f"{half_mi}Mi")
PY
)
echo "Half of max: $HALF_MEM"
Example: if MAX_MEM=512Mi → HALF_MEM=256Mi
Example: if MAX_MEM=1Gi → HALF_MEM=512Mi
4) Update the nosql Deployment (DO NOT delete it)
First, get the container name (Deployment may have a custom container name):
kubectl -n haddock get deploy nosql -o jsonpath='{.spec.template.spec.containers[*].name}{"\n"}'
Now set resources (this updates the Deployment in-place):
kubectl -n haddock set resources deploy nosql \
--requests=memory=128Mi \
--limits=memory=$HALF_MEM
5) Ensure the update rolls out successfully
kubectl -n haddock rollout status deploy nosql
6) Verify the pod has the right requests/limits
kubectl -n haddock get deploy nosql -o jsonpath='{.spec.template.spec.containers[0].resources}{"\n"}'
kubectl -n haddock get pods
Pick the new pod and confirm:
kubectl -n haddock describe pod | sed -n '/Requests:/,/Limits:/p'
You should see:
Requests: memory 128Mi
Limits: memory
If rollout fails (common cause)
If you accidentally set a limit above the namespace max, pods won’t start. Check events:
kubectl -n haddock describe deploy nosql
kubectl -n haddock get events --sort-by=.lastTimestamp | tail -n 20