Kubernetes/CKA

Scheduling - Resource Limits

Ju Young Pang 2025. 3. 16. 21:06

Q) A pod called rabbit is deployed. Identify the CPU requirements set on the Pod in the current(default) namespace
A) 0.5 (500m)

$ k describe po rabbit
Name:             rabbit
Namespace:        default
Priority:         0
Service Account:  default
Node:             controlplane/192.168.193.128
Start Time:       Sun, 16 Mar 2025 11:59:35 +0000
Labels:           <none>
Annotations:      <none>
Status:           Running
IP:               10.22.0.9
IPs:
  IP:  10.22.0.9
Containers:
  cpu-stress:
    Container ID:  containerd://88d17b1b2422c22dc30cd596e37adc6cf34f70e0fdc0d47df65d08c5a5ae4895
    Image:         ubuntu
    Image ID:      docker.io/library/ubuntu@sha256:72297848456d5d37d1262630108ab308d3e9ec7ed1c3286a32fe09856619a782
    Port:          <none>
    Host Port:     <none>
    Args:
      sleep
      1000
    State:          Running
      Started:      Sun, 16 Mar 2025 11:59:38 +0000
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:  1
    Requests:
      cpu:        500m
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-tjzp5 (ro)

 

Q) Another pod called elephant has been deployed in the default namespace. It fails to get to a running state. Inspect this pod and identify the Reason why it is not running.

A) OOMKilled

$ k get po | grep elephant
elephant   0/1     OOMKilled   2 (28s ago)   31s

 

Q) The status OOMKilled indicates that it is failing because the pod ran out of memory. Identify the memory limit set on the POD.

$ k describe po elephant
# 생략
    Limits:
      memory:  10Mi
    Requests:
      memory:     5Mi
# 생략

 

Q) The elephant pod runs a process that consumes 15Mi of memory. Increase the limit of the elephant pod to 20Mi. Delete and recreate the pod if required. Do not modify anything other than the required fields.

$ k get po elephant -o yaml > elephant.yaml
$ k delete po elephant 
pod "elephant" deleted
$ vi elephant.yaml
더보기
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2025-03-16T12:03:13Z"
  name: elephant
  namespace: default
  resourceVersion: "954"
  uid: 65bd6abf-c53e-44d2-860a-1448cfd210e1
spec:
  containers:
  - args:
    - --vm
    - "1"
    - --vm-bytes
    - 15M
    - --vm-hang
    - "1"
    command:
    - stress
    image: polinux/stress
    imagePullPolicy: Always
    name: mem-stress
    resources:
      limits:
        # memory: 10Mi
        memory: 20Mi
      requests:
        memory: 5Mi
$ k apply -f elephant.yaml

 

Q) Inspect the status of POD. Make sure it's running

$ k get po
NAME       READY   STATUS    RESTARTS   AGE
elephant   1/1     Running   0          21s