Wednesday, July 22, 2020

Resource limits -- kubernetes practice problems

A pod named 'rabbit' is deployed. Identify the CPU requirements set on the Pod in the current(default) namespace

Use kubectl describe pods rabbit and see the requests section to understand what is the CPU requirements

master $ kubectl describe pods rabbit
Name:         rabbit
Namespace:    default
Priority:     0
Node:         node01/172.17.0.17
Start Time:   Thu, 23 Jul 2020 02:22:59 +0000
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.244.1.3
IPs:
  IP:  10.244.1.3
Containers:
  cpu-stress:
    Container ID:  docker://be546265915ba81890f23e978f2fabad7dfc14ec470e79f04bcf4418ddc1e6d3
    Image:         ubuntu
    Image ID:      docker-pullable://ubuntu@sha256:55cd38b70425947db71112eb5dddfa3aa3e3ce307754a3df2269069d2278ce47
    Port:          <none>
    Host Port:     <none>
    Args:
      sleep
      1000
    State:          Running
      Started:      Thu, 23 Jul 2020 02:23:07 +0000
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:  2
    Requests:
      cpu:        1
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-5p4qc (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-5p4qc:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-5p4qc
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  2m13s  default-scheduler  Successfully assigned default/rabbit to node01
  Normal  Pulling    2m11s  kubelet, node01    Pulling image "ubuntu"
  Normal  Pulled     2m6s   kubelet, node01    Successfully pulled image "ubuntu"
  Normal  Created    2m5s   kubelet, node01    Created container cpu-stress
  Normal  Started    2m5s   kubelet, node01    Started container cpu-stress


Delete the 'rabbit' Pod. Once deleted, wait for the pod to fully terminate.

master $ kubectl delete pods rabbit
pod "rabbit" deleted



Inspect the pod elephant and identify the status.

See the status section using describe


master $ kubectl describe pod elephant
Name:         elephant
Namespace:    default
Priority:     0
Node:         node01/172.17.0.17
Start Time:   Thu, 23 Jul 2020 02:30:50 +0000
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           10.244.1.4
IPs:
  IP:  10.244.1.4
Containers:
  mem-stress:
    Container ID:  docker://b085f292db9d17c8c9ed22241ac6a6c5363f75d704b707c192a4b1262d650584
    Image:         polinux/stress
    Image ID:      docker-pullable://polinux/stress@sha256:b6144f84f9c15dac80deb48d3a646b55c7043ab1d83ea0a697c09097aaad21aa
    Port:          <none>
    Host Port:     <none>
    Command:
      stress
    Args:
      --vm
      1
      --vm-bytes
      15M
      --vm-hang
      1
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       OOMKilled
      Exit Code:    1
      Started:      Thu, 23 Jul 2020 02:31:14 +0000
      Finished:     Thu, 23 Jul 2020 02:31:14 +0000
    Ready:          False
    Restart Count:  2
    Limits:
      memory:  10Mi
    Requests:
      memory:     5Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-5p4qc (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-5p4qc:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-5p4qc
    Optional:    false
QoS Class:       Burstable
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  51s                default-scheduler  Successfully assigned default/elephant to node01
  Normal   Pulled     27s (x3 over 47s)  kubelet, node01    Successfully pulled image "polinux/stress"
  Normal   Created    27s (x3 over 46s)  kubelet, node01    Created container mem-stress
  Normal   Started    27s (x3 over 46s)  kubelet, node01    Started container mem-stress
  Warning  BackOff    14s (x4 over 43s)  kubelet, node01    Back-off restarting failed container
  Normal   Pulling    0s (x4 over 50s)   kubelet, node01    Pulling image "polinux/stress"



The status 'OOMKilled' indicates that the pod ran out of memory. Identify the memory limit set on the POD.

 See the limits section on the describe logs and note the limits of the memory which is 15 mi in this case.

The elephant runs a process that consume 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.

first execute below command below to get the corresponding yaml file for the elephant pod

kubectl get pods -o wide elephant -o yaml > elephant.yaml

Now vi to the yaml file and change the limit section of memory to increase to 20 mi from 10mi. Save the file and execute the command below

kubectl apply -f elephant.yaml ( Remember to delete the pod before creating new one )







No comments:

Post a Comment